- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Help Regarding Perl Regular Expression(Pattern Mat...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-15-2006 10:36 PM
тАО09-15-2006 10:36 PM
if($x =~ /$y/g) {
#where $x=41 and $y=424143
Please tell me if the above expression will work ?
If not then how to match $x and $y ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-16-2006 04:19 AM
тАО09-16-2006 04:19 AM
Re: Help Regarding Perl Regular Expression(Pattern Matching)
If you are looking to see if the character string "41" held in $x exists in $y (anywhere) then:
# perl -le '$x=41;$y=424143;if ($y =~ /$x/g) {print "ok"}'
...will print "ok".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-16-2006 04:32 AM
тАО09-16-2006 04:32 AM
Re: Help Regarding Perl Regular Expression(Pattern Matching)
An excellent tour and summmary of Perl regular expression syntax, can be found here:
http://perldoc.perl.org/perlre.html
At it's end are additional references, including Jeffrey Friedl's "Mastering Regulare Expressions" --- an outstanding book on the subject.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-16-2006 04:40 AM
тАО09-16-2006 04:40 AM
SolutionJust to see whether a simple (non-wildcard) string is a substring of an other string you should NOT use a regular expression.
Instead, use the 'index' function which is made specifically for that and processes more efficiently:
Same example:
perl -le '$x=41;$y=424143;if (index($y,$x) >= 0 ) {print "ok"}'
(one of many) Online documentation:
#http://www.xav.com/perl/lib/Pod/perlfunc.html#item_index
hth,
Hein van den Heuvel
HvdH Performance Consulting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-16-2006 09:11 PM
тАО09-16-2006 09:11 PM
Re: Help Regarding Perl Regular Expression(Pattern Matching)
The /g modifier is for global matches, and returns more matches if available, changing the context if needed. It also fiddles with global variables and string attributes, so you can match on from the last position with \G metacharacters. The /g modifier is related to the /c modifier.
# perldoc perlretut
About 52% or 1188 lines down is the explanation of /g and /c
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 11:30 PM
тАО09-18-2006 11:30 PM
Re: Help Regarding Perl Regular Expression(Pattern Matching)
perl -le '$x=41;$y=424143;if (index($y,$x) >= 0 ) {print "ok"}'
which is suggested by Hein van Den.
Thanks a lot to all of you.