I have approximately 4000 lines of text. The text string has spaces removed or trimmed from leading side and trailing side of string. I need to do the following:
Example string: This is an example of a text string with several spaces.
Discussion: About 4000 lines each with CRLF are contained in the text file. I need to look at each line, find the first word in the text, replace the space between the first and second word with a comma and then go to the next line. After the comma is inserted or replaced in the text, nothing remaining needs to be preformed on that line. The next line is to be addressed and the process repeated. Thanks for any help.
Larry
Space after first word in string
Moderator: General Moderators
Re: Space after first word in string
show us the code that you are done so far and tell us which are your doubts
Miko
Miko
Re: Space after first word in string
/^(\s*\S+) [ ]/m,$1
Re: Space after first word in string
preg_replace('/\s/', ',', $yourline, 1)
Re: Space after first word in string
Thanks for your help. I'm trying to use this code inside a text editor while allows search and replace with regex. I used the code you provided and also tried other versions of it. It will not allow me to use directly your code
preg_replace('/\s/', ',', $yourline, 1). I just need the expression to use in the search part of the text editor and of course in the replace portion I have placed the comma ',' The text engine only responds to pure regex expression. I hope I have explained this better this time. thanks
preg_replace('/\s/', ',', $yourline, 1). I just need the expression to use in the search part of the text editor and of course in the replace portion I have placed the comma ',' The text engine only responds to pure regex expression. I hope I have explained this better this time. thanks
Re: Space after first word in string
LLSmith wrote:I'm trying to use this code inside a text editor while allows search and replace with regex
no wonder
which text editor are you using?...
try this:
Regex: ([A-Z]+) (.*)
Replace with: \1,\2
Re: Space after first word in string
UltraEdit Studio 09
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: Space after first word in string
Your first regex is almost correct. You need to select the "Perl" Regex style and do this:
[text]Find What:
^([-\w]+)[ ]
Replace With:
$1,[/text]
You need the ^ at the beginning to match words at the beginning of each line only. The above regex matches words having alpha-numerics and dash and underscores only.
[text]Find What:
^([-\w]+)[ ]
Replace With:
$1,[/text]
You need the ^ at the beginning to match words at the beginning of each line only. The above regex matches words having alpha-numerics and dash and underscores only.