• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

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

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
NevSoFly
Asked:
NevSoFly
  • 12
  • 10
  • 5
1 Solution
 
ozoCommented:
[^?]$
0
 
Terry WoodsIT GuruCommented:
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
 
Terry WoodsIT GuruCommented:
@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.

 
ozoCommented:
I meant what I said, but they both match the same set of strings.
0
 
NevSoFlyAuthor Commented:
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
 
ozoCommented:
Can the larger string contain "?" or alphanumeric?
0
 
ozoCommented:
([-+]?[a-z0-9]+)(?![?])
0
 
ozoCommented:
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
 
ozoCommented:
If you also don't want extra alphanumeric from the larger string at the end,
([-+]?[a-z0-9]+)(?![?a-z0-9])
0
 
NevSoFlyAuthor Commented:
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
 
Terry WoodsIT GuruCommented:
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
 
NevSoFlyAuthor Commented:
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
 
Terry WoodsIT GuruCommented:
Perhaps try:
(?<![a-z0-9])([a-z][0-9]*){2,}(?![?])
(Partial credit to @ozo if it works for you)
0
 
ozoCommented:
Can you post an example on which ([-+]?[a-z0-9]+)(?![?a-z0-9]) does not work?
0
 
NevSoFlyAuthor Commented:
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
 
Terry WoodsIT GuruCommented:
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
 
ozoCommented:
Why should it not also match these?
a
8e
2s
3c
-4e
-2s
x
z
6a
2
2a
-b
2xy
6xy
2²yx
0
 
NevSoFlyAuthor Commented:
@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
 
NevSoFlyAuthor Commented:
@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
 
ozoCommented:
([-+¯]?(?:[0-9°¹²³]*[a-z]){2}[a-z0-9°¹²³]*)(?![?a-z0-9°¹²³])
0
 
ozoCommented:
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
 
NevSoFlyAuthor Commented:
@ozo
that was a typo on my part. non of the constant portions should match.
0
 
ozoCommented:
((?:[a-z][0-9°¹²³]*){2}[a-z0-9°¹²³]*)(?![?a-z0-9°¹²³])
0
 
NevSoFlyAuthor Commented:
@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
 
NevSoFlyAuthor Commented:
((?:[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
 
NevSoFlyAuthor Commented:
Once again you've helped me out.  Thanks so much.
0
 
ozoCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 12
  • 10
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now