Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Regex question - capturing next char

by jonadab (Parson)
on Oct 10, 2014 at 10:25 UTC ( [id://1103388]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regex question - capturing next char
in thread Regex question - capturing next char

I think you can do this with a single substitution regex (s/pattern/replacement/;), but it's going to need a lookahead assertion at the end. Also, this is only possible if you can write a regex segment that will consistently match the metadata. (Making it match metadata if there is any and not block matching if there isn't any is then trivial: precede the metadata-match portion in (?: and follow it up with )*.

Perhaps something along these lines...

s/(a(?:[<][^>]+[>])*)a((?:[<][^>]+[>])*(?:\s+|[;,.])+)/$1$2/;

That appears to work with the actual sample data you provided, but I don't know if it will work with your real data.

Replies are listed 'Best First'.
Re^2: Regex question - capturing next char
by QM (Parson) on Oct 10, 2014 at 13:43 UTC
    And for the degenerative case: [<][^>]+[>] does not allow for an empty <> field. Perhaps [<][^>]*[>] is better?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found