Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do you know why my RE does not match my text

Status
Not open for further replies.

sepgs2004

Programmer
Apr 25, 2007
5
0
0
US
This is the input:
<html:text styleId="dateDue" property="newFee.dateDueString" maxlength="10"
onkeyup="autoFormatDate(this, event)" size="10" onkeypress="digitsOnly()"
onfocus="clearTextField(this)" onchange="dude()" />


My Reg expression is:
onkeyup\s*=\s*"autoFormatDate\s*\(this\s*,\s*event\)"[.\s]*onchange\s*=\s*"(.*)"[.\s]*\/>

I am trying to replace the following
<html ....
onkeyup="autoFormatDate(this, event)"
.....
onchange="dude()"
... />


with

<html ....
onkeydown="autoFormatDate(this, event)"
.....
onchange="newDude(); dude()"
... />


In brief, onkeyup replaced with onkeydown and onchange got one more function/script added. There might be anything including line breaks between this onkeyup and onchange properties in a tag. Another thing is I want to replace/update onchange only if the tag also contains onkeyup="autoformat...".

other points
We can assume onchange is going to follow onkeyup in a tag. This line breaks are the complicated ones that I could not get it matched. I am not sure how to make it restricted to one tag at a time instead of the situation "begining matches one tag and ending matches next tag".

With the above, this does not match my Reg expression.

Thanks
 
The bit of the regex
Code:
event\)"[.\s]*onchange
is failing because . inside [] is a real dot, not a match anything .

Is that what you mean?
 
There are quite a few variants of regular expression languages; what language/utility are you doing this in and under what OS?

Try this perl version:

Code:
perl -e '
        # do not read file line-by-line
        local $/=undef;
        while (<>) {
s/onkeyup\s*=\s*"autoFormatDate\s*\(this\s*,\s*event\)"(.*)onchange\s*=\s*"(.*)"/onkeydown="autoFormatDate(this, event)$1onchange="newDude();$2"
/s;
                print;
        }
'

Annihilannic.
 
Good point, Annihilannic - I thought I was on the Perl forum :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top