0

I'm having trouble getting urls to match with

 sregex rex = sregex::compile("(?:ftp|http|https)+://([\\S\^<\^>]+)", sregex::icase ); 

It matches all the urls but it also includes >> on the end of each match, which I'm trying to negate. What am I doing wrong?

1
  • What do you intend [\\S\^<\^>]+ to do? Commented Jan 14, 2013 at 3:35

1 Answer 1

1

I believe what you want is this:

 sregex rex = sregex::compile("(?:ftp|http|https)://([\\S]+[^<>]*)", sregex::icase ); 

The character ^ only means "not" when ^ is the first character of a set. Thus, the ^ in [\\S\^<\^>]+ does not mean "not." When ^ is not the first character of a set, it indicates the beginning of a target sequence or follows a line terminator, or has no special meaning.

Sign up to request clarification or add additional context in comments.

4 Comments

Why does the capture group need a +? (Or the protocol match for that matter?)
I wondered the same thing about the captured group, but left it since it was in the askers original.
Except the OP's was inside the capture group.
+1 Yes, after rereading, the OP appears to only be concerned with < or > at the end, so I have changed it again. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.