Check if two strings are separated by a single hyphen only
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I have a field in my data. I need to check by regex if two strings in that field are delimited/separated by a single hyphen(-) only. No other special characters should be there.
For example:
my field has string ASIAPAC-X722XXX. My regex should give "True" if data is in this format else "False" (since ASIAPAC and X722XXXare separated by a single hyphen only).
If string is ASIAPAC/-X722XXX or ASIAPAC--X722XXX or if any other special character/combination of special characters(even multiple hyphens) are delimiting the strings then regex match should give false.
I have tried using (\S*)-(\S.*) in my regex tool but it is not working as expected. It is working (giving True) only in cases when I replace "-" by any other special char in my string. In the below mentioned screenshot scenario, it should give false.
My 2nd string (X722XXX) is always going to be a 7 digit alphanumeric string (if that helps).
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Awesome! This is what I was looking for. Thanks!
