Jump to content

Removing text from lines automatically? (RegExp?)


myname1
 Share

Recommended Posts

How to remove the bolded texts automatically?

Example 1 - Between "11" and "22":

ab11cde21fg22hi

abc11de21f22ghi

abcd11e2122fghi

Done with Regular Expression, see below.

Example 2 - Between "^*" and "~|" (extra chars):

ab^*cde21fg~|hi

abc^*de21f~|ghi

abcd^*e21~|fghi

Done with Regular Expression, see below.

Example 3 - From first "1" to begin:

ab11cde21fg22hi

abc11de21f22ghi

abcd11e2122fghi

Example 4 - From last "2" to end:

ab11cde21fg22hi

abc11de21f22ghi

abcd11e2122fghi

All help is welcome. :P

Edited by myname1
Link to comment
Share on other sites

StringBetween()

StringLeft()

StringRight()

... ????

automatic is a very open question

8)

I don't know what do you mean. :P Can you explain more? :(

In this case, I see regular expressions as the fastest way to do this. For instance, the first could easily be done by using a regular expression replacement of "11.*?22" with "".

What exactly are you looking for?

Thanks for telling me that. Now I figured out how to use regular expression for the first two examples.

Example 1 done by regular expression:

11.*22

Example 2 done by regular expression:

\^\*.*\~\|

Other two are still undone. I tried this for example 3: ^.*1, but it worked like this:

ab11cde21fg22hi

abc11de21f22ghi

abcd11e2122fghi

Anyone know how to do the trick for last two examples? :idea:

Edited by myname1
Link to comment
Share on other sites

$t = "ab11cde21fg22hi" & @CRLF & "abc11de21f22ghi" & @CRLF & "abcd11e2122fghi"
ConsoleWrite(StringRegExpReplace($t, "(^|\r\n|\n)(\D*1)(.*)", "$1$3") & @LF)
ConsoleWrite(StringRegExpReplace($t, "(.*)(2\D*)(\n|\r\n|$)", "$1$3") & @LF)

Link to comment
Share on other sites

$t = "ab11cde21fg22hi" & @CRLF & "abc11de21f22ghi" & @CRLF & "abcd11e2122fghi"
ConsoleWrite(StringRegExpReplace($t, "(^|\r\n|\n)(\D*1)(.*)", "$1$3") & @LF)
ConsoleWrite(StringRegExpReplace($t, "(.*)(2\D*)(\n|\r\n|$)", "$1$3") & @LF)
Is that "$t ="-line necessary? I mean that if I have more than 3 different lines, that would be a quite huge line.

It's because you are using the greedy star. Use a lazy star instead. "^.*?1"

I can't get that lazy star (*?) working. It gives no results. So lazy star isn't supported in all editors like SciTE?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...