CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Incorporating an array into a regex

 



tallest1
Deleted

May 26, 2000, 5:32 PM

Post #1 of 5 (3265 views)
Incorporating an array into a regex Can't Post

For a regex like this:

$linecont =~ s/<au image full(\d{1,3})([^>]*)>/<img src="$full[$1]"$2>/gi;

I believe I'd get an error for having '$full[$1]' in the regex. Is there a way to incorporate the array without resorting to if..then statements. If not, what is the best way to do what I intend to do?

Thanks in advance.


japhy
Enthusiast / Moderator

May 26, 2000, 6:53 PM

Post #2 of 5 (3265 views)
Re: Incorporating an array into a regex [In reply to] Can't Post

Just put a backslash in front of the [ character.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


s/(foo)(bar)/$1\[$2]/;
</pre><HR></BLOCKQUOTE>


tallest1
Deleted

May 26, 2000, 7:08 PM

Post #3 of 5 (3265 views)
Re: Incorporating an array into a regex [In reply to] Can't Post

are you sure about that?


Assuming $1 equaled 12,
<img src="$full\[$1\]"$2>/ would actually return the contents of $full[12]?

Thanks for replying.


japhy
Enthusiast / Moderator

May 26, 2000, 7:12 PM

Post #4 of 5 (3265 views)
Re: Incorporating an array into a regex [In reply to] Can't Post

I'm sorry, I totally misread your question. Your method is perfectly fine.
I suggest you try it.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


s/(\d+)/$array[$1]/;
</pre><HR></BLOCKQUOTE>

is perfectly fine.


tallest1
Deleted

May 26, 2000, 7:18 PM

Post #5 of 5 (3265 views)
Re: Incorporating an array into a regex [In reply to] Can't Post

Thanks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives