## using regular expressions to extract "adjacent" substrings

## using regular expressions to extract "adjacent" substrings

(OP)

Suppose I have strings of the form:

xxxxxxxxxxZYYYxxxxxx

where x can be any character, Z is some specific character, and Y is a certain character type (i.e. digits) of arbitrarily length. I want to exploit the fact that substring Y...Y always appears after Z, and write a regular expression that extracts Y.

Thank you in advance!

xxxxxxxxxxZYYYxxxxxx

where x can be any character, Z is some specific character, and Y is a certain character type (i.e. digits) of arbitrarily length. I want to exploit the fact that substring Y...Y always appears after Z, and write a regular expression that extracts Y.

Thank you in advance!

## RE: using regular expressions to extract "adjacent" substrings

## CODE --> Perl

YYY

YY

Annihilannic.

tgmlify - code syntax highlighting for your tek-tips posts

## RE: using regular expressions to extract "adjacent" substrings

Would just =~ /\S+Z(Y+)\g

print $1

work (it doesn't in the code).

Thanks, Max

## RE: using regular expressions to extract "adjacent" substrings

Annihilannic.

tgmlify - code syntax highlighting for your tek-tips posts

## RE: using regular expressions to extract "adjacent" substrings

## RE: using regular expressions to extract "adjacent" substrings

Annihilannic

tgmlify - code syntax highlighting for your tek-tips posts

## RE: using regular expressions to extract "adjacent" substrings

## CODE

my@mtc=$mys=~/Z(\d*)/g;

print"@mtc\n";

Franco

http://www.xcalcs.com : Online engineering calculations

http://www.megamag.it : Magnetic brakes for fun rides

http://www.levitans.com : Air bearing pads