最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regex to get the text after first "space"? - Stack Overflow

programmeradmin1浏览0评论

Here a string I need to parse using regex.

.idc?TERRIL_id=1 Crachet 7/12

In fact this is an url followed by 1 space and a text. I need to extract url and the text in 2 separate ways.

To extract the url \S+ is working just fine.

But to extract the text after first space, it gets really hard to understand.

I am using Yahoo Pipes. (I don't know if this link to edit the code will work)

EDIT:

Using (\S+) (.+) gives me something weird:

Here a string I need to parse using regex.

http://carto1.wallonie.be/documents/terrils/fiche_terril.idc?TERRIL_id=1 Crachet 7/12

In fact this is an url followed by 1 space and a text. I need to extract url and the text in 2 separate ways.

To extract the url \S+ is working just fine.

But to extract the text after first space, it gets really hard to understand.

I am using Yahoo Pipes. (I don't know if this link to edit the code will work)

EDIT:

Using (\S+) (.+) gives me something weird:

Share Improve this question edited Sep 29, 2011 at 15:37 Waza_Be asked Sep 29, 2011 at 14:37 Waza_BeWaza_Be 39.6k50 gold badges191 silver badges262 bronze badges 2
  • 3 Please always specify the language or tool you intend to use. Regex implementations vary, and a solution that works in one language may not work in another. – Tom Zych Commented Sep 29, 2011 at 14:39
  • Thanks. Added in first post with link. – Waza_Be Commented Sep 29, 2011 at 14:42
Add a ment  | 

1 Answer 1

Reset to default 4

According to the Pipes documentation, it looks like it uses fairly standard regex syntax. Try this:

^(\S+)\s(.+)$

Then the URL will be $1 and the ment will be $2. The . operator matches any character, which you will need since it looks like the ments may have spaces.

EDIT: changed from literal space to \s since you might be looking at some odd whitespace character(s). You might as well throw a ^ and $ in there too, so the match fails instead of doing something weird.

发布评论

评论列表(0)

  1. 暂无评论