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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Help

Status
Not open for further replies.

JoeMcGarvey

Programmer
Oct 31, 2002
47
US
RegExp experts - can someone help me translate this into a regExp? I want to look for all occurrences of

class="could_be_anything"

and create a regExp string that I can then use in a replace function:

theRepString = ????; //the regExp
strOUT = strOUT.replace(theRepString, ""); //need to modify this to look for all occurrence in strOUT.

Thanks!!


Joe McGarvey - Web Application Developer
Paragraph, Inc. - Paragraph Publisher -
 
try this:
Code:
 /^class="[^"]*"$/
=========================================================
while (!succeed) try();
-jeff
 
No luck... doesn't seem to match the pattern. Any thoughts?

I just can't seem to grasp regExp's. I think I'll start a support group... Regular Expressions Anonymous. "Hi, my name is Joe and Regular Expressions ruined my marriage..."
Joe McGarvey - Web Application Developer
Paragraph, Inc. - Paragraph Publisher -
 
try again:

var s = 'class="could_be_anything"';
alert(/^class="[^"]*"$/.test(s))

=========================================================
while (!succeed) try();
-jeff
 
my version that I literally pulled out of you know where. [lol]
<script language=&quot;javascript&quot;>
function checkReg(str) {
var pattern = /((class=\&quot;)+(\w*)+(\&quot;))/gi;
var strOUT = str.replace(pattern, &quot;pattern worked&quot;);
alert(strOUT);
}
</script>

<form>
<textarea onBlur=&quot;checkReg(this.value);&quot;></textarea>
</form> _________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
hey jemminger. I think it the reason it's not working for the certain application it's being used for is it's only finding one instance of class=&quot;blah&quot; with the ^ (begin) and $ (end)

take those out and add the global ignore case and it would parse a entire page to replace all class=&quot;blah&quot;
/class=&quot;[^&quot;]*&quot;/gi;

I like your pattern by the way. very nice! _________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
onpnt,

thanks for the correction...i should pay closer attention:
that I can then use in a replace function =========================================================
while (!succeed) try();
-jeff
 
isn't there a way to do this without regular expressions? If all you are doing is trying to find elements who have a className then you could just run through all elements with a function that checks the class attribute. I'm just providing you with another angle for your problem, not saying there is anything wrong with your way of doing things. Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top