javascript - Regex match conditional but dont return it -
here trying clear on regexes. i've created regex:
a.match( /(@|#)(.*?)(\s|$|\:)/g )
it matches users , hastags in tweet. problem return condition( @|#) , (\s|$|\:)
is possible not returning them?
i'm using javascript
var ='rt @olmjanssen: met #fbkgames en @jmvanhalst volop in voorbereiding: 6 juni seminar kwaliteitsborging van #sportaccommodatie bij regiseerende gemeente' a.match( /(@|#)(.*?)(\s|$|\:)/g ) //returns ["@olmjanssen:", "#fbkgames ", "@jmvanhalst ", "#sportaccommodatie "]
how about:
a.match(/[@#](\s+)(?:\s|:|$)/g)
explanation:
the regular expression: (?-imsx:[@#](\s+)(?:\s|:|$)) matches follows: node explanation ---------------------------------------------------------------------- (?-imsx: group, not capture (case-sensitive) (with ^ , $ matching normally) (with . not matching \n) (matching whitespace , # normally): ---------------------------------------------------------------------- [@#] character of: '@', '#' ---------------------------------------------------------------------- ( group , capture \1: ---------------------------------------------------------------------- \s+ non-whitespace (all \n, \r, \t, \f, , " ") (1 or more times (matching amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- (?: group, not capture: ---------------------------------------------------------------------- \s whitespace (\n, \r, \t, \f, , " ") ---------------------------------------------------------------------- | or ---------------------------------------------------------------------- : ':' ---------------------------------------------------------------------- | or ---------------------------------------------------------------------- $ before optional \n, , end of string ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
Comments
Post a Comment