
pattern matching starting at end of string
j> All,
j> I need to search for a pattern in a string but instead of starting the
j> search at the beginning of the string I need it to start at the end.
j> So if I had the string "myscriptmycode" and I wanted to search for the
j> pattern "my" I need it to find the second "my" in the string. How can
j> I do this? Can this be done through pattern matching or is there a
j> better way? Any suggestions would be appreciated. Thanks.
With regexps:
1. Use /.*my/
.* will eat as much as possible chars this pattern will match last
'my' string.
2. Intersting technique: reverse string and use reversed pattern
(/ym/).
Using rindex:
1. rindex $str, 'my';
What should you use? It depends on what are you going to do with this
string.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-