Difference between revisions of "FR/Documentation/Expressions Regulieres dans Calc"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Expressions régulières dans Calc et Writer)
m
Line 1: Line 1:
 +
{{Documentation/FR/AideDemandee}}
 
== Introduction ==
 
== Introduction ==
 
En terme simple, les expressions régulières sont une facon astucieuse de trouver du texte.
 
En terme simple, les expressions régulières sont une facon astucieuse de trouver du texte.

Revision as of 13:06, 10 December 2007

Template:Documentation/FR/AideDemandee

Introduction

En terme simple, les expressions régulières sont une facon astucieuse de trouver du texte.


A typical use for regular expressions is in finding text; for instance to locate all cells containing man or woman in your spreadsheet, you could search using a single regular expression.


Expressions régulières dans Calc et Writer

Les expressions régulières sont disponible dans Calc par :

  • Menu - Edition - boite de dialogue 'Rechercher & Replacer'
  • Menu - Données - Filtre - Filtre Standard
  • Les fonctions, comme SOMME.SI, RECHERCHE

The best way to learn about regular expressions in Calc is to start by understanding how to use Find & Replace. This is covered by the 'HowTo for Regular Expressions in Writer', which you should read.


In Calc, regular expressions are applied separately to each cell. (You'll see that regular expressions are applied separately to each paragraph in Writer.) So a search for 'r.d' will match red in cell A1 but will not match 'r' in cell A2 with 'd' (or 'ed') in cell A3. (The regular expression 'r.d' means 'try to match 'r' followed by another character followed by 'd' ').

Expressions régulières dans les fonctions Calc

There are a number of functions in Calc which allow the use of regular expressions:
'SUMIF', 'COUNTIF',
'MATCH', 'SEARCH', 'LOOKUP', 'HLOOKUP', 'VLOOKUP',
'DCOUNT', 'DCOUNTA', 'DSUM', 'DPRODUCT',
'DMAX', 'DMIN', 'DAVERAGE', 'DSTDEV', 'DSTDEVP', 'DVAR', 'DVARP',
'DGET'


Whether or not regular expressions are used is selected on the Tools - Options - OpenOffice.org Calc - Calculate dialog:


Activer l'option 'expressions régulières dans Calc


For example '=COUNTIF(A1:A6;"r.d")' with "Enable regular expressions in formulas" selected will count cells in A1:A6 which contain 'red' and 'ROD'. Additionally if "Search criteria = and <> must apply to whole cells" is not selected then 'Fred', 'bride', and 'Ridge' will also be counted.


Expressions régulières avec la fonction NB.SI


Regular expression searches within functions are always case insensitive, irrespective of the setting of the "Case sensitive" check box on the dialog above - so 'red' and 'ROD' will always be matched in the above example. This case-insensitivity also applies to the regular expression structures ([:lower:]) and ([:upper:]), which match characters irrespective of case.

Regular expressions will not work in simple comparisons. For example: ' A1="r.d" ' will always return FALSE if A1 contains 'red', even if regular expressions are enabled - it will only return TRUE if A1 contains 'r.d' ('r' then a dot then 'd'). If you wish to test using regular expressions, try the 'COUNTIF' function - 'COUNTIF(A1; "r.d")' will return '1' or '0', interpreted as TRUE or FALSE in formulae like '=IF(COUNTIF(A1; "r.d");"hooray"; "boo")'

Activating the "Enable regular expressions in formulas" setting means all the above functions will require any regular expression special characters (such as parentheses) used in strings within formulas, to be "escaped" using a preceding backslash, despite not being part of a regular expression. These backslashes will need removing if the setting is later deactivated.

Expressions régulières dans Calc, rechercher et remplacer

Find & Replace in Calc is very similar to Find & Replace in Writer, as described in the 'HowTo for Regular Expressions in Writer'. The following points are interesting to Calc users:

  • When a match is found, the whole cell is shown highlighted, but only the text found will be replaced. For example, searching for 'brown' will highlight a cell containing 'redbrown clay', and replacing with nothing will leave the cell containg 'red clay'.
  • If a cell contains a hard line break (entered by Cntrl-Enter), this may be found by '\n'. For example if a cell contains 'red hard_line_break clay' then searching for 'd\nc' and replacing with nothing leaves the cell containing 'relay'.
  • The hard line break acts to mark "end of text" as understood by the regular expression special character '$' (in addition of course to the end of text in the cell). For example if a cell contains 'red hard_line_break clay' then a search for 'd$' replacing with 'al' leaves the cell with 'real hard_line_break clay'. Note that with this syntax the hard line break is not replaced - it simply marks the end of text.
  • Using '\n' in the 'Replace with' box will replace with the literal characters '\n', not a hard line break.
  • The Find & Replace dialog has an option to search 'Formulas', 'Values', or 'Notes'. This applies to any search, not just one using regular expressions. Searching with the 'Formulas' option would find 'SUM' in a cell containing the formula '=SUM(A1:A6)'. If a cell contains text instead of a function, the text will still be found - so that the simple text 'SUMMARY' in a cell would also give a match to 'SUM' using the 'Formulas' option.
  • Searching for the regular expression '^$' will not find empty cells. This is intentional - the rationale being to avoid performance issues when selecting a huge number of cells. Note that empty cells will not be found even if you are only searching a selection.
Personal tools