After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 453496 - Snippets has a new placeholder type: regex
Snippets has a new placeholder type: regex
Status: RESOLVED DUPLICATE of bug 460523
Product: gedit
Classification: Applications
Component: docs
git master
Other Linux
: Normal normal
: ---
Assigned To: Maintainers of Gnome user documentation
Gedit maintainers
Depends on:
Blocks:
 
 
Reported: 2007-07-03 20:54 UTC by jessevdk@gmail.com
Modified: 2009-12-29 14:23 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description jessevdk@gmail.com 2007-07-03 20:54:31 UTC
Snippets has a new placeholder type which makes it easy to match and substitute text (this can also be done with python, but is much more verbose). The syntax of the placeholder is as follows:

${[n:]input/regular expression/substitution[/modifiers]}

Legenda:
  - n (optional): the reference tabstop of this placeholder. It's not a real tabstop because you can't tab to it, but you can use it in other placeholders to mirror the result of the substitution
  - input (mandatory): a reference to another placeholder (a number) or an environmental variable ($GEDIT_SELECTED_TEXT). This is the input for the match
  - regular expression (mandatory): a regular expression to match the input. This uses the python re module and thus its syntax
  - substitution (mandatory): the substitution string, this can contain backreferences to groups in the regular expression with \n where n is the number of the group or 0 for the whole match. You can also use group names (see python docs) in the regular expression, you can backreference to those with \<name> (you can also backreference with \<n> where n is a number of a group). Further more, you can have modifiers in a backreference with the following syntax \<n|name,modifiers>. Currently supported modifiers are:
    - u: upper case first character
    - U: upper case whole group
    - l: lower case first character
    - L: lower case whole group
    - t: title case whole group

  You can specify multiple modifiers (very modifier is processed in turn). This means that you can use the modifier Lu to first make the matched group lowercase and then make the first character upper case.

  One more neat thing you can do with substitutions is conditional substitution. The syntax is as follows: (?n|name,truepart,falsepart). This means that truepart will be used when the group n (or name) is non-empty and falsepart otherwise. These can be nested (?1,(?2,yes2,no2),no1) and used wherever in the substitution. The truepart and falsepart can itself contain any backreference.

 - modifiers (optional): python regex modifiers can be specified: I, L, M, S, U and X (example: IMX). For information on the meaning of these modifiers see the python documentation


Examples:

Use placeholder 1 and upper case
${1/.*/\<0,U}

Use placeholder 1 and make only first character upper case
${1/.*/\<0,Lu}

Use selected text and make it title case
${$GEDIT_SELECTED_TEXT/.*/\<0,t>}

Use selected text, substitute yes if it contains the word 'world' and no if not. Also make it a reference
${1:$GEDIT_SELECTED_TEXT/(.*world.*)?/(?1,yes,no)}
Mirror the substitution: $1
Comment 1 jessevdk@gmail.com 2007-07-03 20:56:46 UTC
Oh, and you can escape context sensitive characters with \. So in the conditional substitution case, if you want to use a , in the truepart you can use \,
Comment 2 Paolo Borelli 2009-12-29 14:23:52 UTC
lets track missing snippet docs in a single place.

*** This bug has been marked as a duplicate of bug 460523 ***