Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression 1

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
I am trying to figure out regular expressions, i am terrible at them, I got it to where it will put a link one QXXX x being a number, however i dont know how to get it to where it would do Q and then any ammount of numbers after it....

Thanks

Code:
<%

function ereg(strOriginalString, strPattern, varIgnoreCase,strReplaceWith)
  dim objRegExp : set objRegExp = new RegExp
  with objRegExp
    .Pattern = strPattern
    .IgnoreCase = varIgnoreCase
    .Global = True
  end with
  ereg = objRegExp.replace(strOriginalString, strReplaceWith)
  set objRegExp = nothing
end function


'(Q+\d{3}(?!\d)) = 3 numbers only
Response.write ereg("This is a test i want to see if reg exp Q265 can spot post number Q344 and then output as a link", "(Q+\d{3}(?!\d))", False,"<a href=""/post/?id=$1"">Q$1</a>")

%>

Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]

 
>"(Q+\d{3}(?!\d))"
[tt]"Q+(\d{3})(?!\d)"[/tt]

This will accept even ... Q265abc ... etc. and will exclude abc in the query string and link text description. If you only want to accept only Q...Q265 and no other cases..., you can use simply this.
[tt]"\bQ+(\d{3})\b"[/tt]
You don't need negative look ahead in case you don't have to. (In vbs it's supported by the v5.6. There might still be some legacy version in legacy setup, I don't know, just in case.)
 
Thanks tsuji, but there is one problem with that, i need it to be able to catch any ammount of numbers after the Q because its basicly the same thing as tek-tips does with their post thing ie: thread333-1268902

Jason

Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]

 
>i need it to be able to catch any ammount of numbers after the Q
Then it's okay, you know what you want.
 
I dont know how to catch any ammount of numbers after the Q... ??

Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]

 
But you know "+" already. How about this?
[tt] "Q+(\d+)(?!\d)"[/tt]
 
If you mean starting from minimum 3, then it is this.
[tt] "Q+(\d{3,})(?!\d)"[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top