topical media & game development

talk show tell print

basic-regex-20-NonGrouping.htm / htm



  <html>
  <head>
  <title>Reverse Surname and First Name, using non-grouping parentheses</title>
  <script language="vbscript" type="text/vbscript">
  Function ReverseName2
  Dim myRegExp, TestName, Match
  Set myRegExp = new RegExp
  myRegExp.Pattern = "(\S+)(?:\s+)(\S+)"
  TestString = InputBox("Enter your name below, in the form" & VBCrLf & _
   "first name, then a space then last name." & VBCrLf & "Don't enter an initial or middle name.")
  Match = myRegexp.Replace(TestString, "$2, $1")
  If Match <> "" Then
    MsgBox "Your name in last name, first name format is:" & VBCrLf & Match
  Else
    MsgBox "You didn't enter your name." & VBCrLF & "Press OK then F5 to run the example again."
  End If
  End Function
  
  </script>
  </head>
  <body onload="ReverseName2">
  
  </body>
  </html>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.