Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing text by mm/dd/yy 2

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
I have a LONG string of text that looks like:

06/13/06 this is an entry 7/13/06 another entry 10/12/06 yet another

and I need to break it up into individual strings like:


06/13/06 this is an entry

7/13/06 another entry

10/12/06 yet another

How can I do this - the date is pretty consistent as far as it exists at the start of each entry, but notice that not all single digit months have a zero (i.e. 05/12/06 v. 5/12/06)

[conehead]
 
regexp would be the easiest (and sexiest) way to do it:
Code:
<script type="text/javascript">

var a = "06/13/06 this is an entry 7/13/06 another entry 10/12/06 yet another"

a = a.replace(/(\d{1,2}\/\d{1,2}\/\d{2})/g, "\n$1");

alert(a);

</script>
Take note that this will add a \n to the start of the string, so you may want to manually strip that off after the replace command. Additionally, if you needed to modify it to accomodate for a 4 digit year then you could change the last part of the regexp to \d{[!]4[/!]}

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
kaht with the sexy regex ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Everybody has to have their own form of sex appeal [smile]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Is there anyway to split on a carriage return that is in a db? Does that make sense?

[conehead]
 
do you want to split them completely? so like using an array...

Code:
var myarray = a.split("\r");

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
however if there are other white space characters you do not want to split on, be careful in its use
The whitespace characters consist of:
' ' blank
'\t' tab
'\n' new line
'\f' form feed
'\r' carriage return

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
?
cLFlaVA said:
if you'd like to start spitting threads again
huh?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top