Regular Expression question

# Thread: Regular Expression question

1. Senior Member
Join Date
Dec 1969
Posts
122

## Regular Expression question

How do I ensure that the pattern to be matched matches the beginning of the input? I&#039;ve read that using ^ will do ti, but it didn&#039;t give an example, and I haven&#039;t been able to figure it out. <BR><BR>Suppose I have these two inputs to evaluate:<BR>s = (111 111) &#039; first time<BR>s = 111 111 &#039; second time<BR><BR>Dim re, s<BR>Set re = New RegExp<BR>re.Global = True<BR>re.Pattern = "(d{3})+(s)+(d{3})"<BR><BR>If rs.Test(s) Then<BR> Response.Write "The first character of this string is a digit"<BR>End If<BR><BR>How do I only see this message the second time? I tried "^(d{3})+(s)+(d{3})" but that didn&#039;t work.<BR><BR>I&#039;d appreciate any help.<BR><BR>Thanks!<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
412

## RE: Regular Expression question

you could just use:<BR><BR>d{3}sd{3} for both

3. Senior Member
Join Date
Dec 1969
Posts
1,424

## How to write Regular Expressions

Have a read of this:<BR><BR> http://www.flws.com.au/RegExHowTo.html<BR><BR>See if it help you to look at your problem from a different angle :-)

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Regular Expression question

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vspropattern.asp<BR><BR>What are those + signs in your regexp for???<BR><BR>You have already told the expression to get 3 digits {3}, so you don&#039;t have any character(s) to repeat 1 or more times.<BR><BR>It worked fine when I pulled them out.<BR><BR>You know you do *not* need the parens in there, either, unless you intend to use those 3-digit string later in a REPLACE call.<BR><BR>And surely you don&#039;t intend to need to copy the s into the output of REPLACE? So why put it in parens, ever?<BR><BR>Anyway, both "^d{3}sd{3}" and "^(d{3})s(d{3})" worked great for me.<BR><BR>Do you need a demo?<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## How does that help him...

...discover the pattern only at the beginning of the string?<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•