Sign in to follow this  
Followers 0
typeleven

StringRegExp Trouble

2 posts in this topic

I feel like I'm missing something very obvious here. I have this line...

StringRegExp("tt1234567 tt1231234 4242424","(?:tt)[0-9]{7}",3)

and I get this result (as an array):

tt1234567
tt1231234

but shouldnt I get this?

1234567
1231234

I want to strip out that "tt" and only get things that started with "tt" in the string.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Because you have no matching groups, the whole match is returned. You want to return a group that contains [0-9]{7}, so group it ;) Because you've done that, you don't need to have a non-matching group for the tt.

StringRegExp("tt1234567 tt1231234 4242424","tt([0-9]{7})",3)

I hope you can understand that... I seem to be talking complete gobbledegook when it comes to explaining programming in words, I was showing my design for a new cricket club website to the first team captain, and after explaining the whole way the database is structured for comments he said "So a bit like facebook then?", I could have said "You can comment a bit like facebook." and that would be all :blink:

Mat

Edited by Mat

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0