Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Regex - remove characters (pattern not terminated)

by twaddlac (Novice)
on Jul 01, 2010 at 19:07 UTC ( [id://847590]=note: print w/replies, xml ) Need Help??


in reply to Regex - remove characters (pattern not terminated)

Thank you for all of your help! I finally got it working! However, I have another question. I'm not very familiar with lookarounds but I think that they would increase the throughput of my program exponentially!

I would like to use a lookahead (and/or lookbehind, I don't really know the difference..) assertion after matching a pattern (from a list of patterns) at either the beginning or end of the string. The lookaround would search for an adjacent pattern that is also from the list (NOTE: order does not matter!). If there is no known adjacent pattern, then remove the 6 characters preceding or following the pattern (as we have done already); if there is a pattern, proceed with some other instruction (of which is not relevant). The following is pseudocode to help explain:

$pattern_A = "123"; $pattern_b = "456"; $string_1 = "1234567890"; $string_2 = "1236547890"; # Then apply regex/lookaround to search for adjacent pattern if($adjacent_pattern == false){ remove_pattern_and_six_following_characters; print("string_*"); } else{ do_something_else; print("string_*"); }

The output for $string_1 would be:
string_1 = 1234567890
as it had an adjacent known pattern, the program performed some other function.

The output for $string_2 would be:
string_2 = 0
as it did not have an adjacent known pattern, the pattern that was matched and the following 6 characters were removed.

Let me know if you need to know anything else!! Thank you very much!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://847590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-29 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found