开发者

Regex , How to obtain XXXX, given XXXX-yyyyy+12313123@you.com

开发者 https://www.devze.com 2023-02-07 19:15 出处:网络
Given a email like: XXXX-yyyyy+12313123@you.com I want regex to capture whatever XXXX is, which can开发者_JAVA技巧 be of variable length.

Given a email like: XXXX-yyyyy+12313123@you.com

I want regex to capture whatever XXXX is, which can开发者_JAVA技巧 be of variable length.

In ruby i'm trying:

model_type = to[/^(.*?)\-/,1]

But according to Rubular, that is capturing the trailing -, meaning XXXX- which I don't want. How do I exclude that dash?

Thanks


I just checked rubular and it isn't capturing the trailing -

http://rubular.com/r/UJi4vSMx9H


XXXX can't contain dash symbol, yes?

model_type = to[/^([^-]*)-/, 1]


All these regexes...

"XXXX-yyyyy+12313123@you.com".split('-').first
0

精彩评论

暂无评论...
验证码 换一张
取 消