0

How to regex match words that have digits or any non-characters inside words, excluding when digits and non-characters (\/°†@*()'\s+&;±|-\^) are at the end of word? I need to match dAS2a but not dASI6. Could not adapt the Regex to match string not ending with pattern solution.

dA/Sa dAS2a dASI/ dASI6

http://regex101.com/r/qM4dV7/1 failed.

Community
  • 1
  • 1
gasyoun
  • 23
  • 5
  • Does it have to *start* with a specific character? Are you testing each "word" one at a time or trying to find valid words in a long string? What is a "non-character" (assuming you mean non-letter)? – Sam Oct 16 '14 at 19:09
  • It should _ignore_ numbers or special characters at the end. In middle or beginning - does not matters. I'm trying to find valid words in a long string. "non-character" = non-letter. – gasyoun Oct 16 '14 at 19:11
  • Final question: if you are looking in a long string and a valid word can have non-alphanumeric characters (AKA: anything), what makes the start/end of a word? In other words, what delimits two words? Is it a space? – Sam Oct 16 '14 at 19:13
  • Each word in a new line, so \n. – gasyoun Oct 16 '14 at 19:15

1 Answers1

1

This should work just fine (if you use the gmi modifiers):

^.*[a-z]$

Demo


You said each word is on a new line. Using the m modifier we can anchor each expression to the beginning/end of a line with ^ and $ anchors (without the modifier, this means beginning/end of the string). Then you said a word can essentially be anything (.*) as long as it ends in a non-digit or non-special character (I took that to mean a "letter", [a-z] with the i modifier).

Unihedron
  • 10,902
  • 13
  • 62
  • 72
Sam
  • 20,096
  • 2
  • 45
  • 71
  • I give you my thanks. Can it find only `dAS2a` and not `dA/Sa`? – gasyoun Oct 16 '14 at 19:24
  • You can replace `.*` with a [character class](http://www.regular-expressions.info/charclass.html) of what characters you want to allow. For example, `^[a-z0-9]*[a-z]$` will only match alphanumeric "words" ending in letters. – Sam Oct 16 '14 at 19:30
  • I need to find and weed out "wrong" words, but `^[a-z0-9]*[a-z]$` accepts `dAS2a` as a good word, which it is not, it should locate it or ignore, better locate. – gasyoun Oct 16 '14 at 19:33