views:

383

answers:

1

Hi all guys!

still on regex! i want learn it but i'm still crashing the head into my keybord! ;-)

ok very trivial for you, i'm sure!

Assuming i have this sting, the \s is where the space actualy is... \n where linebreak is..

EDITED:

   OTHERFIELD: Other text here...`\n`
   DESCRIPTION: The quick brown fox jum`\s\n`
   `\s`ps over the lazy dog
   OTHERFIELD: Other text here...`\n`

just for explanation:

each line always start with an UPPERCASE word followed by a colon!

so the only way i have for split each line is by it's last \n for this reason i can't remove it!

then i'm preg_splitting each cleaned line with this regex

/$\R?[^A-Z:]*/m

that give me an array like this:

[DESCRIPTION] => The quick brown fox jumps over the lazy dog

now, what i need to do is remove All the space after the A-Z:

that i have achieved by this regex: /\s+(?![A-Z:])/m that produce this result

DESCRIPTION: The quick brown fox jum ps over the lazy dog

as you can see it leave the space between jum and ps

how to have a result like this?

DESCRIPTION: The quick brown fox jumps over the lazy dog

thank's for the time!

+1  A: 

Try this regular expression:

/\s+\n\s+/

This will match the whitespace only if it’s surrounding a line feed character. You may need to adjust the quantifiers to fit your actual data.

Gumbo
I think he might need to use the /s modifier (treat string as a single line) to make that work.
Zan Lynx
thank's for responce Gumbo, i have tried your regex but unfortunely it don't work, i have updated my question, for better explane!
aSeptik
Why this doesn't work? You need to apply this regexp at the very beginning, before you split your text into lines.
serg
yeah it worked! you are All great guy!
aSeptik
@Zan Lynx: The *s* modifier will only make the `.` to also match line break characters. So `/.*/` matches just a single line while `/.*/s` matches all lines.
Gumbo