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:
Regular expression

 



avalanche
New User

Dec 11, 2012, 6:56 PM

Post #1 of 4 (15150 views)
Regular expression Can't Post

Hello Experts,

I am new to Perl and I face a problem. Unfortunately time is pressing.

I have a script which reads a line starting with a specific string, and parses the line assigning some strings to variables.

if (/^URI configuration/) {
($A,$B) = /^URI\s+configuration\s+for\s+name\s+(\S+)\,\s+URI\s+(\S+)*/;

It works perfect when $uri_name is a single string. However it is possible that this string in the input contains spaces.
The regexp stops at the first space. Also following the string $uri_name there is a number in inside parenthesis that I do not want to parse.

Example line: URI configuration for name Just_name, URI uri name (1073741909)

I want $A = Just_name
$B = "uri name"

Current Regexp works when $B=uri_name

Thanks!


BillKSmith
Veteran

Dec 11, 2012, 8:35 PM

Post #2 of 4 (15140 views)
Re: [avalanche] Regular expression [In reply to] Can't Post

A minor fix to your regexpr will fix the problem as stated.
You probably shoud consider the module Regex::Common::URI::http.

Code
use strict; 
use warnings;
my $line = 'URI configuration for name Just_name, URI uri name (1073741909)';
my ($A,$B) = $line =~ /
^URI\s+configuration\s+for\s+name\s+
([^,]+)
\,
\s+URI\s+
([^(]+)*
\s+\(
/x;
print $A, "\n", $B, "\n";

Good Luck,
Bill


avalanche
New User

Dec 11, 2012, 9:23 PM

Post #3 of 4 (15133 views)
Re: [BillKSmith] Regular expression [In reply to] Can't Post

Thanks so much! It seems to work.


[^something] matches any character except those that [something] denotes; that is, immediately after the leading “[”, the circumflex “^” means “not” applied to all of the rest


Laurent_R
Veteran / Moderator

Dec 11, 2012, 11:17 PM

Post #4 of 4 (15081 views)
Re: [avalanche] Regular expression [In reply to] Can't Post

At the beginning of a cheracter class, the circumflex '^' means that the class includes any character except those explicitely listed after the circumflex.

 
 


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

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