Skip to main content
add "Tilde for nesting structures"
Source Link
jubilatious1
  • 3.9k
  • 10
  • 20

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Either example above: Raku searches for a \{ opening-curlie, .*? zero-or-more instances of any-character (searched non-greedily), followed by a [] square-bracket-delineated group consisting of either \} closing-curlie or (| pipe operator) a $ end-of-string zero-width assertion.

Note: While the code above works, it's probably more correct to write the .*? characters you wish to delete as the custom character class <-[{}]>*?, which translates to "zero-or-more instances of any-character (searched non-greedily) not to include {} opening/closing curly-brace characters" (this is especially important if you anticipateYou should note that this regex solution doesn't address nested bracing). To handle nested bracing, see Tilde for nesting structures.

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Either example above: Raku searches for a \{ opening-curlie, .*? zero-or-more instances of any-character (searched non-greedily), followed by a [] square-bracket-delineated group consisting of either \} closing-curlie or (| pipe operator) a $ end-of-string zero-width assertion.

Note: While the code above works, it's probably more correct to write the .*? characters you wish to delete as the custom character class <-[{}]>*?, which translates to "zero-or-more instances of any-character (searched non-greedily) not to include {} opening/closing curly-brace characters" (this is especially important if you anticipate nested bracing).

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Either example above: Raku searches for a \{ opening-curlie, .*? zero-or-more instances of any-character (searched non-greedily), followed by a [] square-bracket-delineated group consisting of either \} closing-curlie or (| pipe operator) a $ end-of-string zero-width assertion.

You should note that this regex solution doesn't address nested bracing. To handle nested bracing, see Tilde for nesting structures.

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

added 37 characters in body
Source Link
jubilatious1
  • 3.9k
  • 10
  • 20

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Either example above: Raku searches for a \{ opening-curlie, .*? zero-or-more instances of any-character (searched non-greedily), followed by a [] square-bracket-delineated group consisting of either \} closing-curlie or (| pipe operator) a $ end-of-string zero-width assertion.

Note: It'sWhile the code above works, it's probably more correct to write the .*? characters you wish to delete as the custom character class <-[{}]>*?, which translates to "zero-or-more instances of any-character (searched non-greedily) not to include {} opening/closing curly-brace characters" (this is especially important if you anticipate nested bracing).

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Either example above: Raku searches for a \{ opening-curlie, .*? zero-or-more instances of any-character (searched non-greedily), followed by a [] square-bracket-delineated group consisting of either \} closing-curlie or (| pipe operator) a $ end-of-string zero-width assertion.

Note: It's more correct to write the .*? characters you wish to delete as the custom character class <-[{}]>*?, which translates to "zero-or-more instances of any-character (searched non-greedily) not to include {} opening/closing curly-brace characters" (this is especially important if you anticipate nested bracing).

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Either example above: Raku searches for a \{ opening-curlie, .*? zero-or-more instances of any-character (searched non-greedily), followed by a [] square-bracket-delineated group consisting of either \} closing-curlie or (| pipe operator) a $ end-of-string zero-width assertion.

Note: While the code above works, it's probably more correct to write the .*? characters you wish to delete as the custom character class <-[{}]>*?, which translates to "zero-or-more instances of any-character (searched non-greedily) not to include {} opening/closing curly-brace characters" (this is especially important if you anticipate nested bracing).

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

explain custom character class
Source Link
jubilatious1
  • 3.9k
  • 10
  • 20

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Either example above: Raku searches for a \{ opening-curlie, .*? zero-or-more instances of any-character (searched non-greedily), followed by a [] square-bracket-delineated group consisting of either \} closing-curlie or (| pipe operator) a $ end-of-string zero-width assertion.

Note: It's more correct to write the .*? characters you wish to delete as the custom character class <-[{}]>*?, which translates to "zero-or-more instances of any-character (searched non-greedily) not to include {} opening/closing curly-brace characters" (this is especially important if you anticipate nested bracing).

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

Using Raku (formerly known as Perl_6)

At the command line:

~$ raku -pe 's:g/ \{ .*? [ \} | $ ]//;'  file

OR

~$ raku -pe 's:g{ \{ .*? [ \} | $ ] } = "";'  file

Does it have to be Python? Raku is a good choice, especially if you plan on tackling thorny Unicode text via Regular Expressions. Above (example 1) uses the familiar s/// substitution operator. Example 2 uses Raku's newer 'assignment' substitution format, e.g. s{…} = "…".

Either example above: Raku searches for a \{ opening-curlie, .*? zero-or-more instances of any-character (searched non-greedily), followed by a [] square-bracket-delineated group consisting of either \} closing-curlie or (| pipe operator) a $ end-of-string zero-width assertion.

Note: It's more correct to write the .*? characters you wish to delete as the custom character class <-[{}]>*?, which translates to "zero-or-more instances of any-character (searched non-greedily) not to include {} opening/closing curly-brace characters" (this is especially important if you anticipate nested bracing).

Sample Input:

{bc}having or marked by great {a_link|volume} or bulk {bc}{sx|large

Sample Output:

having or marked by great  or bulk 

https://docs.raku.org/language/operators#s///_in-place_substitution
https://raku.org/

Source Link
jubilatious1
  • 3.9k
  • 10
  • 20
Loading