user3871
user3871

Reputation: 12718

Find and replace first occurrence of a space

Given a line of text with two words, such as:

hi hello

How can I replace the first occurrence of a space with a comma, giving desired result:

hi, hello

Sublime text regex ^([^\s]*)(\s) gives:

hihello

Where the gray represents the selected area (notice it's also including the word hi, when it should only include the first space for replacing), which if I ran find replace on, would give:

, hello

Upvotes: 0

Views: 5796

Answers (1)

phatfingers
phatfingers

Reputation: 10250

You capture up to the space and include the captured content in your replacement.

Find what: ^(\S*)\s Replace with: \1,

Upvotes: 2

Related Questions