Page 1 of 1

Replace lines that have no letters or numbers

Posted: Thu Mar 15, 2007 2:33 pm
by shiznatix
I am trying to replace lines in a string that have no letters or numbers but may contain spaces or tabs. Basically I have a string that might look like this:
SPL 2 INVOICE 2121 -19.54 1 Less: Average Employee Cost: $ 224.00 19.54 ? Tax Calculation









SPL 3 INVOICE 5350 1 Taxable Service Fee: 325.60 ? Detail
I want to make it look like this:
SPL 2 INVOICE 2121 -19.54 1 Less: Average Employee Cost: $ 224.00 19.54 ? Tax Calculation
SPL 3 INVOICE 5350 1 Taxable Service Fee: 325.60 ? Detail
I have to use coldfusion for this so I have tried this:

Code: Select all

<cfset works = REReplace(#works#, "^[a-z0-9A-Z]", "", "ALL")>
but alas, it does nothing.

Posted: Thu Mar 15, 2007 3:08 pm
by Kieran Huggins
replacing this:

Code: Select all

^[\s]+$
with nothing helps reduce the line spacing to 1 line...

play here: http://www.cuneytyilmaz.com/prog/jrx/

Posted: Thu Mar 15, 2007 3:42 pm
by shiznatix
Kieran Huggins wrote:replacing this:

Code: Select all

^[\s]+$
with nothing helps reduce the line spacing to 1 line...

play here: http://www.cuneytyilmaz.com/prog/jrx/
awesome tool! ok but still troubles. I gave it my string which is a big help and now I am trying stuff. I would think that this would be what I want:

Code: Select all

[^a-zA-Z0-9]$
because i want a whole line that have no a-z or A-Z or 0-9. That should match lines that are only spaces or only tabs but it does not. Some help?

Posted: Thu Mar 15, 2007 3:49 pm
by Luke

Code: Select all

^[^a-zA-Z0-9]+$
maybe... ?

Posted: Thu Mar 15, 2007 3:51 pm
by shiznatix
I got it!

Code: Select all

\r\n]\s*([\r\n]|\Z)
is what I needed. Thanks for the awesome tool as well.

sorry,

Code: Select all

^[^a-zA-Z0-9]+$
does not work.

Posted: Thu Mar 15, 2007 3:59 pm
by Luke
are you doing it line by line... if not that shouldn't work.

Posted: Thu Mar 15, 2007 4:23 pm
by Kieran Huggins
how about

Code: Select all

^.*\w.*$
?

Posted: Sat Mar 17, 2007 5:43 am
by cyphpdn
Kieran Huggins wrote:how about

Code: Select all

^.*\w.*$
?
Hi Kieran and others,

Here is Cüneyt (of JRX). This post got my attention through Google Alerts and I've wanted to clarify one thing.

The answer should be

Code: Select all

^\s*?$
Note the ? after *, it says the matching should be non-greedy. Without it, JS matches all consecutive whitespaces (incl. newlines) in one go.

Hope this helps.

Posted: Sat Mar 17, 2007 12:25 pm
by Kieran Huggins
Thanks Cüneyt - and welcome to the forum! You have many fans here ;)

And thanks again for your awesome work on JRX - it's getting better and better!

Wow... every time I add a tool to my signature it's author joins the forum! Maybe I should add Google as well... Larry? Sergey? What do you guys think?

Posted: Sat Mar 17, 2007 1:19 pm
by nickvd
:bow: :bow: :bow: :bow: :bow: :bow:

I bow to you Cüneyt... Your regex tool has saved me hours of hair pulling frustration.

Posted: Fri Mar 23, 2007 2:13 pm
by cyphpdn
nickvd wrote:I bow to you Cüneyt... Your regex tool has saved me hours of hair pulling frustration.
:oops: Stop, I'm blushing :) Well, indeed debugging regexps with usual methods can be really time-consuming. I'm really glad if JRX saved you some time.

Hey Kieran, many many thanks for your active promoting, I really appreciate that :)

Peace, and keep on regexping!

Posted: Fri Mar 23, 2007 2:44 pm
by Kieran Huggins
What can I say - I promote awesomeness - you've earned it ;)