Search and replace
-
i cannot fix the regular expressions fort that :/
**Suppose You have this text: **
some text …
some other text.**I would get this text: **
Some text some other text
-
Let me get this straight: you want to change a space, ellipses, newline into just a space? That seems like it would be exceedingly easy to implement, and I find it hard to believe you’ve told us the whole story.
I’m going to embed a snippet of advice I’m starting to copy/paste in at least some of my regex responses:
FYI: if you have further regex needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backword to get things working for you. If you need help formatting the data so that the forum doesn’t mangle it (so that it shows “exactly”, as I said earlier), see this help-with-markdown post, where @Scott-Sumner gives a great summary of how to use Markdown for this forum’s needs.
Normally, I would give the first answer “for free”, and then quote that paragraph, to encourage the questioner to show reasonable effort before future questions. But for this question… I think it needs more of a teaching moment than just handing the answer to you. I will, however, start with a few hints:
- If you want to match a newline, you have to use regular expression syntax or extended syntax.
- If you’re using the regular expression syntax instead of searching/replacing just plain characters, you’ll need to make sure you’ve selected “☑ Regular Expression” in the Replace dialog.
- You can represent a newline character, in Regular Expression or Extended mode, as
\r\n
(for Windows CRLF line endings), as\n
(for Linux LF line endings) – both of these work either in the Find What or the Replace with. - The special regex sequence
\R
works as a generic line ending which matches either Windows or Linux line endings, but only in the Find What field, and only in full Regular Expression mode, not in Extended mode - The ellipsis character (the single character that was in your post – though I don’t know which you typed) is different than the three period ASCII representation of an ellipsis:
…
vs...
.- If you want to be able to include the actually ellipsis character, you will probably have to copy/paste it to get it into the Find What field
- If you are using the three-dot version, you should know that a period has special meaning when in “☑ Regular Expression” mode. To escape it, add a \ before the period, so to match a three-dot ellipsis, you would use
\.\.\.
in your regular expression
- Someplace in this post, I’ve actually shown the Find What regular expression (assuming an ellipsis character)
-----
A couple hints for formatting your response:- embed regular expressions between
`
tick marks, like` …\R`
. It will format it in red and monospace, easily marking it as a regex (those tick marks aren’t part of the regular expression, so don’t put them in the Find What) - embed sample data (both input and output) in one of two ways shown in this help-with-markdown post, which I also linked in my quoted text. Doing it one of those ways will help us make sure we aren’t missing something from your example data
-
well…
f you.
-
I was in the process of adding the following:
Sorry, rereading my post, I think my paragraph was a bit harsh. I guess if you didn’t know about the “Regular expression” tickbox, or know what the regular expression for a newline is, it’s not “exceedingly easy”.
Then I saw your reply. I’m still sorry I was a bit harsh. And you can feel what you like, and can choose not to appreciate my help. But honestly, the entire answer to your question was in my post. If you cannot be bothered to read and understand the post, and instead resort to cursing me out (however abbreviated), well … that’s unfortunate for you.
-
Pardon my Zinger.
I thought this is easy to answer - just giving me the simple syntax. But apparently not. I am not a programmer and do not want to take lesson. Thanks for the trouble. -
@Krokodils-Freundin said:
I thought this is easy to answer - just giving me the simple syntax
Well, I can’t even tell what the question really is. I read the OP and decided to “move on”. @PeterJones is a trooper and went above-and-beyond in his first response (which BTW I don’t consider harsh).
-
The question is: what expression should i use to change a space, ellipses, newline, space into just a space
-
I will try one more time. Every piece of information you need is in my post. But I will be explicit for you.
I said in my detailed post that I had included the right regular expression in my post. My original interpretation of “space, ellipsis, newline” matches exactly with the regular expression I gave in my example of how to highlight regular expressions: "
…\R
" (don’t include the quotes). So that’s what you would plug into the Find What field: a space, the ellipsis character, and the\R
. (if you need it to match another space after the newline, which I couldn’t see in your data – so either got mangled by the forum or your browser, or you didn’t include; for that, you would add another space after the\R
, for “…\R
” – again, don’t include the quotes.) In the Replace with, you would just use a single space. Then you would tick the Regular Expression box. Then everything should work.Of course, TIMTOWTDI, so here are alternate regular expressions that will probably accomplish what you want, too:
\x20…\r\n\x20
: exactly space, exactly ellipsis, exactly CR, exactly LF, exactly space\h…\v+\h*
: match exactly one horizontal space (space or tab), the ellipsis, one or more vertical spaces (which is any CR, LF, etc), and zero or more horizontal spaces\h*…\v+\h*
: similar, but could match zero or more spaces at the beginning, in case you skipped the space, or double spaced, or something.\s*…\s*
: match zero or more spaces (horizontal or vertical), the ellipsis, zero or more spaces
(all of those go in Find What; the Replace With should still be a single space)
-
Thank You PeterJones.
...\n...