Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: String replacement

by Laurent_R (Canon)
on Sep 14, 2015 at 13:52 UTC ( [id://1141932]=note: print w/replies, xml ) Need Help??


in reply to Re^2: String replacement
in thread String replacement

Yes, maybe it works, but I can't comment much on it without having seen the data, which you haven't shown yet.

One thing, though: if you need an atom or a sub-pattern once and only once, then you don't need a quantifier such as {1}, that's what the regex engine will do anyway by default. So that this slightly simpler substitution should do the same thing:

$loop_variable =~ s/ ?[A-Za-z] (\[(.*)\])? ?\d+(.*)?\.+(.*)?//g;
I believe the rest of the regex could probably be improved. For example something like .* is rarely a good idea (.*? is often better), and (\[(.*)\])? is probably better written as (\[(.*?)\])? or as (\[[^]]*\])? (untested). That's just one example.

But I would need to see the data and to know what exactly you find significant in the strings you are trying to match (what are the invariants that you are looking for and what are the variable parts) before I could really give more informed advice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-25 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found