Click to See Complete Forum and Search --> : How can you find the length of a regexp match...?


nickpelling
01-04-2003, 12:50 PM
Hi everyone,

This is a (hopefully) pretty self-explanatory question: if you're searching for a regexp match where the number of characters in the actual match may vary (ie, where you're using regexp features like +, *, or ?), how can you find out what the length of an actual match is, without re-parsing the regexp by hand?

For example, if I'm searching for:-

"Nick +Pelling"

...and want to retain the spacing of the original string, regardless of how many spaces there are there, how do I find out the length of any given match?

Thanks, ....Nick Pelling....

AdamBrill
01-04-2003, 01:01 PM
Try this:

TheNameOfYourString.length

That will return the number of characters in the string

nickpelling
01-04-2003, 03:30 PM
Great explanation, thanks Dave! :-)

Best regards, .....Nick Pelling.....