Mixim
Mixim

Reputation: 972

JavaScript regexp matching

When I use AJAX query to server, it return me string value. This string have predefined format like:

1|#||4|2352|updatePanel|updatePanelID

<table style="width:100%">
<tr>
<td>
</td>
</tr>
</table>

<table id="requiredTable"/>
<tbody>

<tr>
<th>column1</th>
<th>column2</th>
</tr>

<tr style="cursor:pointer" onclick="FunctionName(11111, 22222, 3);">
<td>trColumn1Info</td>
<td>trColumn2Info</td>
</tr>

some other information

I want to get second arguments value of FunctionName by regular expression. I tryed to use next regexp, but it always return null:

var forTest = ajaxResultStr.match(/FunctionName\((\S*)\)/g);
alert(forTest);

Can anybody tell me, whats wrong in my pattern? Thanks in advance

Upvotes: 0

Views: 55

Answers (3)

Harpreet Singh
Harpreet Singh

Reputation: 2671

RegEx you can use

FunctionName\((.+?),(.+?),

Demo

The last element of the result is your output.

//output
//["FunctionName(11111, 22222,", "11111", " 22222"]

Upvotes: 0

Barmar
Barmar

Reputation: 782693

Your regexp only matches when there are no spaces between ( and ). Since there are spaces between the arguments, it doesn't match. Try:

var forTest = ajaxResultStr.match(/FunctionName\([^,]+,\s*([^,]+),.*\)/);

forTest[1] will contain the second argument.

Upvotes: 1

Federico Piazza
Federico Piazza

Reputation: 31035

You can use this regex:

FunctionName.*?,\s*(\w+)

Working demo

enter image description here

Upvotes: 1

Related Questions