By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Skip and pass part of each line in selected text

P: 1
Hi everybody,

Currently I am working on an function in which I want to tag certain parts of text.

This is what I have now :

Expand|Select|Wrap|Line Numbers
  1.       case "djenter":
  2.     var selection = str;
  3.         if(selection){
  4.     selection = selection.replace(/  /gi, ' ');
  5.     selection = selection.replace(/\n/gi,']\n[dj=');
  6.     selection = selection.replace(/\f/gi,']');
  7.     selection = selection.replace(/\r/gi,']');
  8.     selection = selection.replace(/\)\]/gi, '\)');
  9.     selection = selection.replace(/ \(/gi, '\] \(');
  10.     selection = selection.replace(/ \]/gi, '\]');
  11.     selection = selection.replace(/\[dj=hosted by /gi, "Hosted by [dj=").replace(/\[dj=live : /gi, "LIVE : [dj=").replace(/\[dj=live /gi, "LIVE [dj=").replace(/\ vs. /gi, "] vs. [dj=").replace(/\ vs /gi, "] vs [dj=").replace(/\ aka /gi, "] aka [dj=").replace(/\ \& /gi, "] \& [dj=").replace(/\[dj=dj /gi, "dj [dj=").replace(/\[dj=mc /gi, "mc [dj=").replace(/\ live]/gi, "] LIVE");
  12.         bbcode.insertAtCursorEx("[dj=" + selection,"]",select_flag);
  13.     }else{
  14.         alert("Je dient wel eerst een selectie te maken van DJ's welke geslitst worden doormiddel van een ENTER");
  15.     }
  16.         break;
The above will tag a for example the following text :

------------------------
Reload-R & D-Ablo
Masochist & Re-Style
D-Spirit & Sceletor
The Viper & Partyraiser
J:D:A:
Evil Activities
Paul Elstak & MC Ruffian
Endymion & Nosferatu
Dione & Headbanger
Angerfist
Tommyknocker & Bike
Outblast & Catscan
Vinyl Junk
Vince
------------------------

Into the following :

------------------------
[dj=Reload-R] & [dj=D-Ablo]
[dj=Masochist] & [dj=Re-Style]
[dj=D-Spirit] & [dj=Sceletor]
[dj=The Viper] & [dj=Partyraiser]
[dj=J:D:A:]
[dj=Evil Activities]
[dj=Paul Elstak] & mc [dj=Ruffian]
[dj=Endymion] & [dj=Nosferatu]
[dj=Dione] & [dj=Headbanger]
[dj=Angerfist]
[dj=Tommyknocker] & [dj=Bike]
[dj=Outblast] & [dj=Catscan]
[dj=Vinyl Junk]
[dj=Vince]
------------------------

The above works fine, but I would like it also to be possible to let the function beable to exclude the time values in the example below :

22:00 22:45 Reload-R & D-Ablo
22:45 23:30 Masochist & Re-Style
23:30 00:15 D-Spirit & Sceletor
00:15 01:00 The Viper & Partyraiser
01:00 01:30 J:D:A:
01:30 02:15 Evil Activities
02:15 03:00 Paul Elstak & MC Ruffian
03:00 03:45 Endymion & Nosferatu
03:45 04:30 Dione & Headbanger
04:30 05:00 Angerfist
05:00 05:45 Tommyknocker & Bike
05:45 06:30 Outblast & Catscan
06:30 07:15 Vinyl Junk
07:15 08:00 Vince

So the time values are ignored and only the names after the times are tagged the same way as given in the first example.

If tried different ways using the \d{2}\:\d{2} - \d{2}\:\d{2}/gi method but can't seem to get it to work.

Can anybody help me on my way?

Kind regards and thanks in advance!
Jun 17 '07 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,390
hi ...

did you miss the opening slash / ? the following works, so your regEx should work too:

Expand|Select|Wrap|Line Numbers
  1. var check = /\d{2}\:\d{2} - \d{2}\:\d{2}/gi.test('12:23 - 14:34 test');
  2.  
  3. // check is true ;)
  4.  
the two slashes are required until these are the literals to create a valid regEx ...

kind regards
Jun 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.