Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

php - Regex for picking a Value After "-"

Hi I need a Regex that can actually get any letter that is inserted after "-" dash e.g i have a string that says

 "UpTown-R" , "Category-C"

What I get in return is "R" , "C".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If is always the last part of the string, you can do this

/[^-]+$/

see it here on Regexr

[^-] is a character class that matches everything that is not a dash

+ quantifier means one or more of the preceding element

$ anchor for the end of the string


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...