Re: Regex for spaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I can actually use both expressions. Sometimes i get files that have underscores and spaces together in the same file name lol.

----- Original Message -----
From: Joel Roth <joelz@xxxxxxxxx>
To: blinux-list@xxxxxxxxxx
Date: Tue, 21 Nov 2023 09:44:52 -1000
Subject: Re: Regex for spaces

> Oh, the regex I provide doesn't handle the case
> of filenames containing spaces.
>
> That's why my pay grade is so low (zero, actually :-)
>
> Try this:
>
> -p '^\s*(.+?)\s*$' -r '$1'
>
> (.+?) means capture one or more characters but stop where the next
> expression matches (non-greedy).
>
>
> On Tue, Nov 21, 2023 at 08:27:32AM -1000, Joel Roth wrote:
> > Glad to, Rob!
> >
> > -p '^\s*(\S+)\s*$' -r '$1'
>
> > ^ anchor to beginning of string
> > \s* zero or more space characters
> > (\S+) one or more non-space characters, parentheses capture this as $1
> > $ anchor to end of string
> >
> > be sure to use the -d option first to make sure you're
> > getting what you want. I didn't test this.
> >
> > The classic 'rename' perl script is almost the same,
> > but does not recurse through directories for you (you'd have
> > to use 'find' for that'). The search and replace expressions
> > are separated by slashes. '-n' is for simulate only.
> >
> > rename -n 's/^\s*(\S+)\s*$/$1/' [filenames here]
> >
> > Have fun!
> >
> > On Tue, Nov 21, 2023 at 09:34:45AM -0600, 'Rob Hudson' via blinux-list@xxxxxxxxxx wrote:
> > > I am not good with regexes at all. They give me a headache lol. Can anyone supply me a regex that will remove any trailing spaces in front or at the end of a file name? I use the program brename:
> > > https://github.com/shenwei356/brename/
> > > I have a regex to remove double spaces, but now I need one that will knock off leading and trailing.
> > > Thanks for any help.
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups "blinux-list@xxxxxxxxxx" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an email to blinux-list+unsubscribe@xxxxxxxxxx.
> > >
> >
> > --
> > Joel Roth
> >
> > --
> > You received this message because you are subscribed to the Google Groups "blinux-list@xxxxxxxxxx" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to blinux-list+unsubscribe@xxxxxxxxxx.
> >
>
> --
> Joel Roth
>
> --
> You received this message because you are subscribed to the Google Groups "blinux-list@xxxxxxxxxx" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to blinux-list+unsubscribe@xxxxxxxxxx.
>
>

-- 
You received this message because you are subscribed to the Google Groups "blinux-list@xxxxxxxxxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blinux-list+unsubscribe@xxxxxxxxxx.




[Index of Archives]     [Linux Speakup]     [Fedora]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]