Sublime Forum

Regex paragraph search fails

#1

I have a document with many paragraphs. I define a paragraph as

[newline]text consisting of one or more sentences[newline]

I want to convert the paragraphs to have <p> at the beginning and </p> at the end. To begin with I’ve tried to search for paragraphs, using regular expression search, with the following search term:

^*$

When I click Find, search doesn’t find anything. What am I doing wrong?

0 Likes

#2

^.*$

post must at least 10 chars

0 Likes

#3

@jfcherng Thanks. Your search string works. I have a follow-up question. How can I do a search and replace where the original paragraph is retained, but paragraph tags are placed at the beginning and end? In other words,

abcdefg

is converted to

<p>abcdefg</p>

0 Likes

#4

<p>$0</p>


You should be also interested in regex capture group. (not sublime-text-related)
$0 = the whole matched string
$1 = the 1st captured group
$2 = the 2nd captured group
… etc

0 Likes

#5

It works! Thanks.

0 Likes

#6

I’ve never heard of this. Where would I learn about it?

0 Likes

#7

maybe https://regexone.com/lesson/capturing_groups. the concept is really simple.

0 Likes