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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use reglar expressions in sub-string search 1

Status
Not open for further replies.

notmeatleast

Programmer
May 25, 2004
8
FR
Hi,
I want to use regular expressions to find the index in the string that matches the pattern.
someting like:
string first <regular expresion> <string>

e.g. string first {^abc(" ")*$} "abc rf"
blah blah blah

Could you giude me through this.

Thanks
 
I think you need to use either "string" or "regexp".
Using "regexp" you need to use the "-indices" switch.
For example:
set s "abc_123_xyz"
regexp -indices {[^a-z]} $s a

now "a" has the index values.

I think "string" is slightly faster, but you have to match a string, not a regular expression (I think).



Bob Rashkin
rrashkin@csc.com
 
It does help to some extent.
But I need somthing like this:

set str "abcd d "
set patrn "d"
regexp { ($patrn)(" ")*) $str res

and

regexp { (" $patrn")(" ")*} $str res

But regexp is not able to substitute $patrn to d until I use "", and if I use "", it doensn't allow me to search for a space after that, saying there are extra characters after the close quote.

What should be the right regular expression for this situation? I've tried a lot today, but didn't work out.
:-(
 
I'm not sure what you're trying to accomplish but in your example,
regexp "$patrn *" $str res
and
regexp " $patrn *" $str res
both return 1.

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top