The string should contain only one hyphen, eg.if the string is ABC-123, then I need to fetch ABC
You may match on the following pattern:
^[^-]+
This will match the first part of a hyphenated input. It also will match the entire input should the input not have any hyphen at all.
Here is a regex demo .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.