java regex : getting a substring from a string which can vary

后端 未结 5 1601
借酒劲吻你
借酒劲吻你 2021-01-22 19:53

I have a String like - \"Bangalore,India=Karnataka\". From this String I would like to extract only the substring \"Bangalore\". In this case the regex

5条回答
  •  滥情空心
    2021-01-22 20:50

    Are you somehow forced to solve this using one regexp and nothing else? (Stupid interview question? Extremely inflexible external API?) In general, don't try to make regexes do what plain old programming constructs do better. Just use the obvious regex, and it it doesn't match, return the entire string instead.

提交回复
热议问题