473,322 Members | 1,421 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,322 software developers and data experts.

Regular Expression Syntax Help

I'm trying to get the right syntax for my regular expression. The
string I'm trying to parse is:

# myString
[USELESS DATA]
Name: David Dude
[USELESS DATA]

Right now, I'm using the following code:
pattern_Name= '''(?x)
Title:\s+(\w+)\s+
'''
names = re.findall(pattern_Name, myString)
print names

This prints out a list containing only the first names. I want to
search the string until it finds a '\n' endline, but I experimented
with that, and couldn't find what I need.

Feb 7 '06 #1
4 1199
The word "Title" there should be "Name".

What I really need is the pattern for getting the entire string after
"Name: " until a '\n' is found.

Feb 7 '06 #2
try this. maybe this is what you want?

reg = re.compile('Name:.*\\n', re.IGNORECASE)

Feb 7 '06 #3
So now I need to add the requirement that only "Name:" 's which are
followed by

"Request: Play" or "Request: Next" ANYWHERE between the previous titles
and the new titles. Can I use RE's for that ?
Ernesto wrote:
I'm trying to get the right syntax for my regular expression. The
string I'm trying to parse is:

# myString
[USELESS DATA]
Name: David Dude
[USELESS DATA]

Right now, I'm using the following code:
pattern_Name= '''(?x)
Title:\s+(\w+)\s+
'''
names = re.findall(pattern_Name, myString)
print names

This prints out a list containing only the first names. I want to
search the string until it finds a '\n' endline, but I experimented
with that, and couldn't find what I need.


Feb 7 '06 #4
Oh! yes you can use re for that.
You just need to change the pattern a bit

I did not understand where the "title" will be so I have ignored it,
but I got something below which will be helpful for you
value = """name:asasasasas\nrequest: play\ntitle"""
reg = re.compile('Name:.*\\nrequest:.....', re.IGNORECASE)
re.findall(reg, value) ['name:asasasasas\nrequest: play'] value2 = """name:asasasasas\nrequest: next\ntitle"""
reg = re.compile('Name:.*\\nrequest:.....', re.IGNORECASE)
re.findall(reg, value2) ['name:asasasasas\nrequest: next']


Feb 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Lasher | last post by:
Hello, I would like to create a set of very similar regular expression. In my initial thought, I'd hoped to create a regular expression with a variable inside of it that I could simply pass a...
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...
3
by: LordHog | last post by:
Hello all, I am attempting to create a small scripting application to be used during testing. I extract the commands from the script file I was going to tokenize the each line as one of the...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
5
by: Noah Hoffman | last post by:
I have been trying to write a regular expression that identifies a block of text enclosed by (potentially nested) parentheses. I've found solutions using other regular expression engines (for...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.