For an academic assignment, I need to make a regular expression to match a word with the following specifications:
- Word length >= 1 and <= 8
- Contains letters, digits, and underscore
- First digit can only be a letter
- Word is not A,X,S,T or PC,SW
I tried this regex but can’t continue (My big problem is to make the word not equal to PC and SW)
([a-zA-Z&&[^AXST]])|([a-zA-Z][\w]{0,7})
But in the previous regex I didn’t handle the that it is not PC and SW
Thanks,
(?:^|\s)(?!PC)(?!SW)(?!A|S|T|X)(\w{1,8})Explain this?
Highly suggest using an interactive regex tool for things like this. I use either http://regex.powertoy.org/ or http://gskinner.com/RegExr/ Then just play with them till you get it…