jskopek
02-18-2007, 05:46 PM
Hello everyone!
First time visiting these boards - I've been developing web apps for about 5 years, so hope I'll be able to contribute to the community here. In the meantime I'm working on a problem I just can't seem to solve.
I'm creating a snippet of code that analyzes a string called string_of_content - this string contains a whole bunch of HTLM form information, and looks a little like
Are you happy? <br/>
<input type="radio" name="rb_test" value="Yes"> Yes <br/>
<input type="radio" name="rb_test" value="No">No
I want to create a regular expression that finds all radio inputs and erases the value, however I'm bumping into a very frustrating problem.
I decided the easiest way to start would be to find all code blocks (< something >) with a type of radio, so I created this regular expression:
sub regexp_find_radio = new RegExp
with regexp_find_radio
.pattern = "<.*type=""radio"".*>:
.global = True
end with
string_of_content = regexp_find_radio.replace(string_of_content, "!")
This should replace all the inputs of type radio with an exclamation mark, but it isn't so simple... because I specified for the regexp to find 0-infinite characters of type . (anything), this expression includes everything in the string, including the > at the end.
The expression could be 1/2 fixed by changing it to "<.*type=""radio""[^>]*>" so it includes everything that isn't a >, followed by the > that ends the match; however, this does not solve the problem as the .* at the beginning still selects everything.
I need to find a way to create the part of the regular expression that selects every character up to "type=". I thought about using lookaheads, but apparently they are only supported by Perl.
Does anyone know how I would go about creating a regular expression that does what I need? I'd really appreciate any help :)
Edit:
I solved the problem by simply creating a few regular expressions and using a couple of IFs
First time visiting these boards - I've been developing web apps for about 5 years, so hope I'll be able to contribute to the community here. In the meantime I'm working on a problem I just can't seem to solve.
I'm creating a snippet of code that analyzes a string called string_of_content - this string contains a whole bunch of HTLM form information, and looks a little like
Are you happy? <br/>
<input type="radio" name="rb_test" value="Yes"> Yes <br/>
<input type="radio" name="rb_test" value="No">No
I want to create a regular expression that finds all radio inputs and erases the value, however I'm bumping into a very frustrating problem.
I decided the easiest way to start would be to find all code blocks (< something >) with a type of radio, so I created this regular expression:
sub regexp_find_radio = new RegExp
with regexp_find_radio
.pattern = "<.*type=""radio"".*>:
.global = True
end with
string_of_content = regexp_find_radio.replace(string_of_content, "!")
This should replace all the inputs of type radio with an exclamation mark, but it isn't so simple... because I specified for the regexp to find 0-infinite characters of type . (anything), this expression includes everything in the string, including the > at the end.
The expression could be 1/2 fixed by changing it to "<.*type=""radio""[^>]*>" so it includes everything that isn't a >, followed by the > that ends the match; however, this does not solve the problem as the .* at the beginning still selects everything.
I need to find a way to create the part of the regular expression that selects every character up to "type=". I thought about using lookaheads, but apparently they are only supported by Perl.
Does anyone know how I would go about creating a regular expression that does what I need? I'd really appreciate any help :)
Edit:
I solved the problem by simply creating a few regular expressions and using a couple of IFs