473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Regular expression - Matching return characters

I want regular expression which can extract the data between two symbols,
e.g:
<*skdjflsk (new line character)
lksdjfklasjdfl (new line character)
ksjdfkhasdkf (new line character)
asdfjkhasdjk skfhsa (new line character)
sdkfjklsd
*>

The no of lines may not be fix, those may vary. But the whole string will
be in included in (<*text*>).
Mar 2 '07 #1
6 4139
miller
1,089 Expert 1GB
The only challenge to this problem is being familiar with the regular expression modifiers documented here:

http://perldoc.perl.org/perlre.html

You simply want to add the /s modifier so that . will match return characters as well. Then it's a simple grouping like you've already done.

Expand|Select|Wrap|Line Numbers
  1. my $string = qq{foo<*skdjfl\nlksd\nasdkf\nk skfhsa\nlsd\n*>bar};
  2. my ($match) = $string =~ m/(<\*.*?\*>)/s;
  3.  
- Miller
Mar 2 '07 #2
I tried the given regular expression but i am not getting the required o/p
i give my complete string below,

<*COMMAND1*> <*PASS/FAIL*> <*OUTPUT of COMMAND*>
<*COMMAND2*> <*PASS/FAIL*> <*OUTPUT of COMMAND*>
.
.
.
______________________ END ________________________________


I want COMMAND part in $1 ,
PASS/FAIL in $2 ,
and
OUTPUT of COMMAND $3
my control expression i given below,
until ($resultarr[$loopcntl] =~/END/i ) {
if($resultarr[$loopcntl] =~ /\<\*(.*)\*\>\s*\<\*(.*)\*\>\s* \<\*(.*)\*\>/) {
store the $1 $2 $3 in hash
}

i am getting command part in $1 , PASS/FAIL in $2 and OUTPUT of COMMAND $3 but only when all these three things present in one line,
if the OUTPUT of COMMAND goes to next line it not able to collect the string
in $3.

I hope that this explanation will be sufficient to get read of problem.....
Mar 5 '07 #3
KevinADC
4,059 Expert 2GB
where is the 's' modifier Miller mentions in his post?
Mar 5 '07 #4
I check 's' option at the end of regular expression for if condition,
until ($resultarr[$loopcntl] =~/END/i ) {
if($resultarr[$loopcntl] =~ /\<\*(.*)\*\>\s*\<\*(.*)\*\>\s* \<\*(.*)\*\>/s) {
store the $1 $2 $3 in hash
}
Mar 5 '07 #5
Due to your help i can able to solve this problem,


Thanks for your help......
Mar 6 '07 #6
miller
1,089 Expert 1GB
Your welcome. Glad we could help.

- Miller
Mar 6 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
5
by: John | last post by:
I am new in Regular Expression. Could someone please help me in following expression? 1. the string cannot be empty 2. the string can only contains AlphaNumeric characters. No space or any...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
7
by: Tizzah | last post by:
What is wrong with that? regex = /^(http|https):\/\/+({1}+)*\.{2,5}(({1,5})?\/.*)?$/ if(field.hpage.value != regex.test(field.hpage.value)){ alert("Bad Homepage") field.hpage.focus()...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
7
by: blaine | last post by:
Hey everyone, For the regular expression gurus... I'm trying to write a string matching algorithm for genomic sequences. I'm pulling out Genes from a large genomic pattern, with certain start...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.