Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need pattern to match string without a "?" at the end of it.

Posted on 2013-12-03
27
Medium Priority
?
325 Views
Last Modified: 2013-12-03
I need a pattern to match an alphanumeric string (data codes) that does not have a "?" at the end of it.  For example:
   x2
   -hj
   +kl11
   d3k2
Would be matched but:
   x2?
   -hj?
   +kl11?
   d3k2?
Would not be.
0
Comment
Question by:NevSoFly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 10
  • 5
27 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39694163
[^?]$
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39694164
Try this:
[a-zA-Z0-9]+$

Open in new window

If you also want to match the - or + characters, then use this:
[a-zA-Z0-9+-]+$

Open in new window

0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39694166
@ozo, did you mean:
[^?]+$
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 84

Expert Comment

by:ozo
ID: 39694170
I meant what I said, but they both match the same set of strings.
0
 

Author Comment

by:NevSoFly
ID: 39694199
I should have informed you before:
The data codes can be anywhere inside of a larger string.  
There are no capital letters.
The codes are delimited by - and or +

I have tried ([a-z][0-9]*){2,}[^?], but this also matches 1 extra character to the right of the string.
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694203
Can the larger string contain "?" or alphanumeric?
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694206
([-+]?[a-z0-9]+)(?![?])
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694212
note that in d3k2?
"d3k" is alphanumeric string that has a "2", not a "?" at the end of it, inside the larger string "d3k2?"
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694229
If you also don't want extra alphanumeric from the larger string at the end,
([-+]?[a-z0-9]+)(?![?a-z0-9])
0
 

Author Comment

by:NevSoFly
ID: 39694251
ozo,
the larger string will have alphanumeric characters and can have ? but the ?s will be at the end of a different data code that I will also want to ignore.

d3k2 is the entire data code.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39694285
If you're still not getting the result you want, it would probably be worth posting a sample of the large strings that you're dealing with.
0
 

Author Comment

by:NevSoFly
ID: 39694309
TerryAtOpus,
I really wish it was that simple.  My betters are discussing it.

([a-z][0-9]*){2,} seems to do everything that I want, except that it also matches data codes with a "?" at the end.  

For example it matches the substring xc whether or not it is in +xc- or +xc?-
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39694318
Perhaps try:
(?<![a-z0-9])([a-z][0-9]*){2,}(?![?])
(Partial credit to @ozo if it works for you)
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694323
Can you post an example on which ([-+]?[a-z0-9]+)(?![?a-z0-9]) does not work?
0
 

Author Comment

by:NevSoFly
ID: 39694376
OK, I must apologize for not being able to give you all the info that I knew you needed in the first place.  You guys have helped me out a lot in the past.

this is some of the exact sample data "a+(8e-(2s/3c)-4e-2s)*((x/z)6a+xc?-(¯3e¹¹ax²cb/2)*2a)-b+(6z²²xy/2xy)-(6xy/2²yx)".

The data codes that I mentioned before are actually the variables in the expression.  I am attempting to match all terms with multiple variables.  This includes the variables themselves and their exponents.  For instance in the sample data the pattern should match ¯3e¹¹ax²cb, 6z²²xy, xy, xy and yx but not xc as it has a"?" after it.

This is the pattern that has gotten me the closest "([a-z][0-9]*){2,}" but it matches everything including xc.

Again my apologies.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39694392
Interesting that your data includes super scripted numbers ¹²  and you seem to want them in your result too. Did you include them in your pattern at all? (because I don't think [0-9] will match them)
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694405
Why should it not also match these?
a
8e
2s
3c
-4e
-2s
x
z
6a
2
2a
-b
2xy
6xy
2²yx
0
 

Author Comment

by:NevSoFly
ID: 39694414
@TerryAtOpus
sorry, this is the correct pattern "([a-z][°¹²³45678¿]*){2,}!?" that I was using.

@ozo
I only need to match the variable portion of terms with multiple variables because they represent a certain condition.
0
 

Author Comment

by:NevSoFly
ID: 39694421
@TerryAtOpus
for some reason the pattern will not display correctly.  It looks fine when I paste it but once I submit it it changes.  it should read as: ([a-z][0123456789]*){2,}!? the 0-9 is subscript.

@ozo
the variable portions of 2xy, 6xy and 2²yx do need to match.
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694427
([-+¯]?(?:[0-9°¹²³]*[a-z]){2}[a-z0-9°¹²³]*)(?![?a-z0-9°¹²³])
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694429
Why do the constant portions of 2xy, 6xy and 2²yx not match, when the constant portions of ¯3e¹¹ax²cb, 6z²²xy match?
0
 

Author Comment

by:NevSoFly
ID: 39694446
@ozo
that was a typo on my part. non of the constant portions should match.
0
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 39694448
((?:[a-z][0-9°¹²³]*){2}[a-z0-9°¹²³]*)(?![?a-z0-9°¹²³])
0
 

Author Comment

by:NevSoFly
ID: 39694455
@ozo
([-+¯]?(?:[0-9°¹²³]*[a-z]){2}[a-z0-9°¹²³]*)(?![?a-z0-9°¹²³])  doesn't work but
([-+¯]?(?:[°¹²³]*[a-z]){2}[a-z°¹²³]*)(?![?a-z°¹²³])  almost works.  The only mistakes that I can see is that is captures the exponent of the constant of the last term (2²yx) and for some reason if I remove the ? from xc it matches +xc.
0
 

Author Comment

by:NevSoFly
ID: 39694463
((?:[a-z][0-9°¹²³]*){2}[a-z0-9°¹²³]*)(?![?a-z0-9°¹²³]) seems to work correctly.  I also tried a variation of your pattern:  ((?:[a-z][°¹²³]*){2}[a-z°¹²³]*)(?![?a-z°¹²³]).  This also seems to work.  any insight on why?
0
 

Author Closing Comment

by:NevSoFly
ID: 39694465
Once again you've helped me out.  Thanks so much.
0
 
LVL 84

Expert Comment

by:ozo
ID: 39694472
If you ignore leading constants, there is nothing in
"a+(8e-(2s/3c)-4e-2s)*((x/z)6a+xc?-(¯3e¹¹ax²cb/2)*2a)-b+(6z²²xy/2xy)-(6xy/2²yx)"
for which [0-9°¹²³] matches anything different from [°¹²³]
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

671 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question