Problem with Regular Expression

F

fgarciarico

I'm getting crazy with a problem using regular expression. I wanna
search a string into a text and replace it the found string with the
next code, but it doesn't work and I don't know why:

new String(str_found).replace(myRe2,'<span class="bgyellow">$1</
span>');

It finds the string from myRe2, but it shows

<span class="bgyellow">$1</span>

Can anybody help me?

Thanks in advance for your help!
 
M

Martin Honnen

new String(str_found).replace(myRe2,'<span class="bgyellow">$1</
span>');

It finds the string from myRe2, but it shows

<span class="bgyellow">$1</span>

$1 is the first submatch, if you want the complete match use $&. If that
does not help show us your regular expression.
 
F

fgarciarico

Yes Martin, it works. Thanks for your help! But can you explain me
what means "$1 is the first submatch"?
 
M

Martin Honnen

But can you explain me
what means "$1 is the first submatch"?

If you use () in your regular expression then each use will be stored as
a submatch and $n accesses the nth submatch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,155
Latest member
JuliW73391
Top