Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 04-12-2009, 03:59 PM Regex
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Is it possible to have a regex function find all text within two square brackets

['PLAYER', '29', '280.4', '90.5', 'Benito Basso']

so it just gets 'PLAYER', '29', '280.4', '90.5', 'Benito Basso'
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 04-13-2009, 05:20 AM Re: Regex
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
What's your goal? A RegEx for this seems a bit much -- you could just trim off the first and last character too or, if you want to have an array, you could explode by ',' and trim [, ', and ] characters from the first and last entry in the array.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 04-13-2009, 05:46 AM Re: Regex
Average Talker

Posts: 17
Name: Dmitry
Trades: 0
it should be the following:

Code:
\[(.+)\]
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
dimok is offline
Reply With Quote
View Public Profile
 
Old 04-13-2009, 06:06 AM Re: Regex
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
theres going to be loads of [player,x,x,x,x,] etc.
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 04-13-2009, 06:21 AM Re: Regex
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
When i use that regex it just returns "."
Code:
var regexstring = new RegExp("\[(.+)\]");
var myregexp =regexstring.exec(data);
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 04-13-2009, 06:52 AM Re: Regex
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Size doesn't seem to matter:

HTML Code:
<html>
<head>
<script>
var square_bracket_text = "[";
var prefix_string = "";
for (var i=0;i<1000;i++) {
  square_bracket_text += prefix_string + "'" + (Math.floor(Math.random(0,1)*100)) + "'";
  prefix_string = ",";
}
square_bracket_text += "]";

function demo() {
  document.getElementById('original').innerHTML = square_bracket_text;
  document.getElementById('results').innerHTML = square_bracket_text.substring(1,square_bracket_text.length-1);
}
</script>
</head>
<body onLoad="demo();">
<div id="original"></div>
<div id="results"></div>
</body>
</html>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Regex
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26113 seconds with 12 queries