473,399 Members | 4,177 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,399 software developers and data experts.

Help w/ regex for parsing parameters

I have to process parameter input strings of key/value pairs /key=value where
value _may_ contain a slash /.

Here is a sample input string:

/def=gamma chain (FT2) /name=NULL /p_id=CF11423:SF7 /fn=Defense/receptor member
/process=Signal transduction /len=98
Here is the regex:

\s*(?<val>.*?)\s*=
Here is the output:

0: ""
1: "def"
2: "gamma chain (FT2) "
3: "name"
4: "NULL "
5: "p_id"
6: "CF11423:SF7 "
7: "fn"
8: "Defense"
9: "receptor member /process"
10: "Signal transduction "
11: "len"
12: "98"

Everything is fine *except* for the /fn value, I don't want it to split between
defense and receptor. Is this possible w/ a regex, or should I just code my
own split routine to handle this case?
Nov 16 '05 #1
2 2170
I'm no regex guru, but you can try this one- works for your test string, and
gives key/value pairs as named groups.

/(?<key>[^=]*)=(?<value>.*?)(?=\s/|$)

"Julie" <ju***@nospam.com> wrote in message
news:41***************@nospam.com...
I have to process parameter input strings of key/value pairs /key=value
where
value _may_ contain a slash /.

Here is a sample input string:

/def=gamma chain (FT2) /name=NULL /p_id=CF11423:SF7 /fn=Defense/receptor
member
/process=Signal transduction /len=98
Here is the regex:

\s*(?<val>.*?)\s*=
Here is the output:

0: ""
1: "def"
2: "gamma chain (FT2) "
3: "name"
4: "NULL "
5: "p_id"
6: "CF11423:SF7 "
7: "fn"
8: "Defense"
9: "receptor member /process"
10: "Signal transduction "
11: "len"
12: "98"

Everything is fine *except* for the /fn value, I don't want it to split
between
defense and receptor. Is this possible w/ a regex, or should I just code
my
own split routine to handle this case?

Nov 16 '05 #2
Philip Rieck wrote:

I'm no regex guru, but you can try this one- works for your test string, and
gives key/value pairs as named groups.

/(?<key>[^=]*)=(?<value>.*?)(?=\s/|$)


Nice -- works like a charm! Thanks!
Nov 16 '05 #3

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

Similar topics

4
by: Chuck Haeberle | last post by:
I have an interesting regular expression challenge for someone more experienced with them than I for a data layer class... I need an expression to search a SQL statement (any type, SELECT INSERT...
1
by: Julie | last post by:
Suppose a string of the following format: /field=value string /field2=value string2 /field3=value string3 where field is , , and _ value string is any alphanumeric text that doesn't...
13
by: Chris Lieb | last post by:
I am trying to write a regex that will parse BBcode into HTML using JavaScript. Everything was going smoothly using the string class replace() operator with regex's until I got to the list tag....
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
4
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
3
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.