regex question

T

Tim B

Hello,
I am trying to come up with a single regex that will match all strings like
the following, where param1, someOtherParam and yetAnotherParam are literals
and foo, bar and yetAnotherValue can be any group of letters or digits

?param1=foo
&someOtherParam=bar
&yetAnotherParam=yetAnotherValue

I want to manipulate the part after the "=" in each string

So far I have [[\\?]&][a-zA-Z_0-9]+=([a-zA-Z_0-9]+) which matches all the
above plus any with any letter/digits string in place of param1,
someOtherParam or yetAnotherParam.

Is there something I can put in the pattern instead of the first
[a-zA-Z_0-9]+ that will match exactly one of param1, someOtherParam or
yetAnotherParam?
 
T

Tim B

Tim B said:
Hello,
I am trying to come up with a single regex that will match all strings like
the following, where param1, someOtherParam and yetAnotherParam are literals
and foo, bar and yetAnotherValue can be any group of letters or digits

?param1=foo
&someOtherParam=bar
&yetAnotherParam=yetAnotherValue

I want to manipulate the part after the "=" in each string

So far I have [[\\?]&][a-zA-Z_0-9]+=([a-zA-Z_0-9]+) which matches all the
above plus any with any letter/digits string in place of param1,
someOtherParam or yetAnotherParam.

Is there something I can put in the pattern instead of the first
[a-zA-Z_0-9]+ that will match exactly one of param1, someOtherParam or
yetAnotherParam?

Answering my own post here, but I found a solution to my problem, though not
the precise problem I posted.Changing the regex to
[[\\?]&]([a-zA-Z_0-9]+)=([a-zA-Z_0-9]+)
and capturing the first group with Matcher.group(1) allows me to decide if I
want to use the match found with Matcher.find()
 
J

Jussi Piitulainen

Tim said:
Tim B wrote in message ....
?param1=foo
&someOtherParam=bar
&yetAnotherParam=yetAnotherValue

I want to manipulate the part after the "=" in each string

So far I have [[\\?]&][a-zA-Z_0-9]+=([a-zA-Z_0-9]+) which matches
all the above plus any with any letter/digits string in place of
param1, someOtherParam or yetAnotherParam.

Is there something I can put in the pattern instead of the first
[a-zA-Z_0-9]+ that will match exactly one of param1,
someOtherParam or yetAnotherParam?

Answering my own post here, but I found a solution to my problem,
though not the precise problem I posted.Changing the regex to
[[\\?]&]([a-zA-Z_0-9]+)=([a-zA-Z_0-9]+) and capturing the first
group with Matcher.group(1) allows me to decide if I want to use the
match found with Matcher.find()

You can use (param1|someOtherParam|yetAnotherParam) to match and
capture any one of the three strings.

There is an expression that means [a-zA-Z_0-9]. I think it is \w, for
"word character".

Your [[\\?]&] looks weird to me. I would use [?&].

So [?&](\w+)=(\w+).
 
T

Tim B

Jussi Piitulainen said:
Tim said:
Tim B wrote in message ...
?param1=foo
&someOtherParam=bar
&yetAnotherParam=yetAnotherValue

I want to manipulate the part after the "=" in each string

So far I have [[\\?]&][a-zA-Z_0-9]+=([a-zA-Z_0-9]+) which matches
all the above plus any with any letter/digits string in place of
param1, someOtherParam or yetAnotherParam.

Is there something I can put in the pattern instead of the first
[a-zA-Z_0-9]+ that will match exactly one of param1,
someOtherParam or yetAnotherParam?

Answering my own post here, but I found a solution to my problem,
though not the precise problem I posted.Changing the regex to
[[\\?]&]([a-zA-Z_0-9]+)=([a-zA-Z_0-9]+) and capturing the first
group with Matcher.group(1) allows me to decide if I want to use the
match found with Matcher.find()

You can use (param1|someOtherParam|yetAnotherParam) to match and
capture any one of the three strings.

There is an expression that means [a-zA-Z_0-9]. I think it is \w, for
"word character".

Your [[\\?]&] looks weird to me. I would use [?&].

So [?&](\w+)=(\w+).

Thanks Jussi. I made the changes and it appears to work fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

RegEx 0
Collect Excel Data from Website 5
Regex replace problem 2
XSD datatypes 0
extracting urls 7
Creating a regex to get multiple values and print 0
Regular expression search and replace 25
compound regex 0

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top