capture « Regular Expression « Javascript Data Type Q&A

Home
Javascript Data Type Q&A
1.Array
2.Clojure
3.date
4.decimal
5.function
6.global
7.loop
8.math
9.number
10.object
11.Regular Expression
12.scope
13.String
14.Var
15.variable
Javascript Data Type Q&A » Regular Expression » capture 

1. Regex to capture variables    stackoverflow.com

I am trying to use an HTML form and javascript (i mention this, because some advanced features of regex processing are not available when using it on javascript) to acomplish the ...

2. Regex To Match &entity; or &#0-9; And Capture &    stackoverflow.com

I'm trying to do a replace on the following string prototype: "I‘m singing & dancing in the rain." The following regular expression matches the instance properly, but also captures the character ...

3. What's a good regular expression to capture the root domain of a given url?    stackoverflow.com

Ideally, I'd like to capture foo.com from something like http://foo.com/bar?param=value or https://www.foo.com Thanks. Edit: Sorry for the vagueness. I'll be doing this in Javascript. 2nd Edit: I should post ...

4. Javascript Regex - capture everything except C-style comments    stackoverflow.com

The problem: I'm trying to style certain keywords (e.g. "function") within the content of a code-tag, excluding those keywords from the C-style comments that appear in that content. Solution: I believe ...

5. Regular expression, "just group, don't capture", doesn't seem to work    stackoverflow.com

x = "abcdefg"
x = x.match(/ab(?:cd)ef/)
shouldn't x be abef? it is not, it is actually abcdef Why is it that my ?: not having any effect? (of course my understanding could very well ...

6. Regex is capturing the whole string    stackoverflow.com

I am using the following regex:

(public|private +)?function +([a-zA-Z_$][0-9a-zA-Z_$]*) *\\(([0-9a-zA-Z_$, ]*)\\) *{(.*)}
To match the following string:
public function messenger(text){
sendMsg(text);
}
private function sendMsg(text){
alert(text);
}
(There is no line breaks in the string, they are converted to whitespaces ...

7. problem with named capture in Javascript Regular Expression    stackoverflow.com

I have got the following regular expression working just fine in Rad Software Regular Expression designer.

param\s+name\s*=\s*"movie"\s+value=\s*"(?<target>.*?)"
And now I am wondering, how to get this to work in JavaScript. It keeps on ...

8. What am I doing wrong with my regex?    stackoverflow.com

I am trying to capture "Rio Grande Do Leste" from:

...
<h1>Rio Grande Do Leste<br />
...
using
var myregexp = /<h1>()<br/;

var nomeAldeiaDoAtaque = myregexp.exec(document);
what am I doing wrong? update: 2 questions remain: 1) searching (document) didn“t produce ...

9. how do I capture something after something else? like a referer=someString    stackoverflow.com

I have ref=Apple and my current regex is

    var regex = /ref=(.+)/;
    var ref = regex.exec(window.location.href);
    alert(ref[0]);
but that includes the ref= now, I ...

10. REGEX: Capture Filename from URL without file extention    stackoverflow.com

So I am trying to create a Javascript Regex that captures the filename without the file extension. I have read the other posts here and 'goto this page:

11. Find the start index (in string) of capture [JS/RegExp]    stackoverflow.com

Is there anyway I can find the index (in string) of my RegExp capture? eg ...

var str = "hello world";
var regex = /lo (wo)/;
var match = regex.exec(str);
// what I want is ...

12. Need a regular expression to capture second level domain (SLD)    stackoverflow.com

i need a regular expression to capture a given URLs SLD. Examples:

jack.bop.com -> bop
bop.com -> bop
bop.de -> bop
bop.co.uk -> bop
bop.com.br -> bop
All bops :). So this regex needs to ignore ccTLDs, gTLDs ...

13. Javascript Regex Match Capture is returning whole match, not group    stackoverflow.com

re = /\s{1,}(male)\.$/gi

"A girl is a female, and a boy is a male.".match(re);
this results in " male." what i want is "male" I put male in parenthesis and I though that would capture ...

14. Named capturing groups in JavaScript regex?    stackoverflow.com

As far as I know there is no such thing as named capturing groups in JavaScript. What is the alternative way to get similar functionality?

15. Capture groups with javascript regex    stackoverflow.com

I have a url string from which I want to capture all the words between the / delimiter: So given this url:

"/way/items/add_items/sell_items":
I want to capture:
way
items
sell_items
add_items
If I do it like this:
'/way/items/sell_items/add_items'.match(/(\w+)/g)
=> [ 'way', ...

16. JavaScript regular expression with capturing parentheses    stackoverflow.com

I have this paragraph:

<p>FIRST SECOND THIRD</p>
and I want to wrap the second word in a SPAN like so:
<p>FIRST <span>SECOND</span> THIRD</p>
If I do this:
text.replace(/\s(\w+)\s/, '<span>$1</span>');
the space characters before and after the ...

17. Javascript RegEx non-capturing prefix    stackoverflow.com

I am trying to do some string replacement with RegEx in Javascript. The scenario is a single line string containing long comma-delimited list of numbers, in which duplicates are possible. An ...

18. Replace a Regex capture group with uppercase in Javascript    stackoverflow.com

I'd like to know how to replace a capture group with its uppercase in JavaScript. Here's a simplified version of what I've tried so far that's not working:

> a="foobar"
'foobar'
> a.replace( /(f)/, ...

19. capturing group in regex    stackoverflow.com

I am exploring capturing groups in Regex and I am getting confused about lack of documentation on it. For ex, can anyone tell me difference between two regex:

/(?:madhur)?/
and
/(madhur)?/
As per me, ? ...

20. Capture every URL in text    stackoverflow.com

Possible Duplicate:
regex to find url in a text
Can I get a regular expression that will capture every URL from a string, I'd like to ...

21. Regular expression to capture 3 strings in quotation marks separated by space    stackoverflow.com

ok, I guess the code says it all.

//I have this string.
var str = '"Watch out" "for the" "rock!"'
//this is one of the many patterns that I tried
res=str.match(/"(.*)" "(.*)" "(.*)"/g)
I want an ...

22. Regex non capturing groups in javascript    stackoverflow.com

I'm a bit rusty on my regex and javascript. I have the following string var:

var subject = "javascript:loadNewsItemWithIndex(5, null);";
I want to extract 5 using a regex. This is my regex:
/(?:loadNewsItemWithIndex\()[0-9]+/)
Applied like ...

23. Rubular versus javascript regexp capture groups    stackoverflow.com

Noticed a difference between what Rubular.com and Javascript regexes:

'catdogdogcatdog'.match(/cat(dog)/g);  // JS returns ['catdog', 'catdog']  
I expected to capture 'dog' twice but instead I get 'catdog' twice. Rubular captures 'dog' twice ...

24. What does regex [\0-\uffff] capture?    stackoverflow.com

As I am reading through someone else's JavaScript, I encountered this regex charset:

[\0-\uffff]
What exactly is captured by this?

25. Javascript Regex back-reference not populating all capturing groups    stackoverflow.com

Strange one here (or maybe not), I am attempting to retrieve two capturing groups via Javascript regex, first group: one or more digits (0-9), second group: one or more word characters ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.