Replace lines that have no letters or numbers

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Replace lines that have no letters or numbers

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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/
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Code: Select all

^[^a-zA-Z0-9]+$
maybe... ?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

are you doing it line by line... if not that shouldn't work.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

how about

Code: Select all

^.*\w.*$
?
cyphpdn
Forum Newbie
Posts: 2
Joined: Sat Mar 17, 2007 5:39 am

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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.
cyphpdn
Forum Newbie
Posts: 2
Joined: Sat Mar 17, 2007 5:39 am

Post 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!
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

What can I say - I promote awesomeness - you've earned it ;)
Post Reply