Anda di halaman 1dari 13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

Documentation/HowTos/RegularExpressionsin
Writer
DeApacheOpenOfficeWiki
<Documentation
|HowTos

Contenido
1Introduction
2WhereregularexpressionsmaybeusedinOOo
3Asimpleexample
4Theleastyouneedtoknowaboutregularexpressions
5HowregularexpressionsareappliedinOpenOffice.org
6Literalcharacters
7Specialcharacters
8Singlecharactermatch.?
9Repeatingmatch+*{m,n}
10Positionalmatch^$\<\>
11Alternativematches|[...]
12POSIXbracketexpressions[:alpha:][:digit:]etc..
13Grouping(...)andbackreferences\x$x
14Tabs,newlines,paragraphs\t\n$
15Hexadecimalcodes\xXXXX
16The'Replacewith'box\t\n&$1$2
17TroubleshootingOOoregularexpressions
18TipsandTricks

Introduction
Insimpleterms,regularexpressionsareacleverwaytofind&replacetext(similarto'wildcards').Regular
expressionscanbebothpowerfulandcomplex,anditiseasyforinexperienceduserstomakemistakes.We
describetheuseofOpenOffice.orgregularexpressionsaimingtobeclearenoughforthenovice,whiledetailing
theaspectsthatcancauseconfusiontomoreexperiencedusers.
AtypicaluseforregularexpressionsisinfindingtextinaWriterdocumentforinstancetolocatealloccurrences
ofmanorwomaninyourdocument,youcouldsearchusingaregularexpressionwhichwouldfindbothwords.
Regularexpressionsareverycommoninsomeareasofcomputing,andareoftenknownasregexorregexp.
Notallregexarethesamesoreadingtherelevantmanualissensible.
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

1/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

WhereregularexpressionsmaybeusedinOOo
InWriter:
EditFind&Replacedialog
EditChangesAccept/rejectcommand(Filtertab)
InCalc:
EditFind&Replacedialog
DataFilterStandardfilter&Advancedfilter
Certainfunctions,suchasSUMIF,LOOKUP
InBase:
FindRecordcommand
Thedialogsthatappearwhenyouusetheabovecommandsgenerallyhaveanoptiontouseregularexpressions
(whichisoffbydefault).Forexample

https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

2/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

Youshouldcheckthestatusoftheregularexpressionoptioneachtimeyoubringupthedialog,asitdefaultsto
'off'.

Asimpleexample
Ifyouhavelittleornoexperienceofregularexpressions,youmayfinditeasiesttostudytheminWriterrather
thansayCalc.
InWriter,bringuptheFindandReplacedialogfromtheEditmenu.
Onthedialog,chooseMoreOptionsandticktheRegularExpressionsbox
IntheSearchboxenterr.dthedotheremeans'anysinglecharacter'.
ClickingtheFindAllbuttonwillnowfindalltheplaceswhereanrisfollowedbyanothercharacterfollowedby
ad,forinstance'red'or'hotrod'or'bride'or'yourdog'(thislastexampleisrfollowedbyaspacefollowedby
dthespaceisacharacter).
IfyoutypexxxintotheReplacewithbox,andclicktheReplaceAllbutton,thesebecome'xxx','hotxxx',
'bxxxe','youxxxog'
Thatmaynotbeveryuseful,butitshowstheprinciple.We'llcontinuetousetheFindandReplacedialogto
explaininmoredetail.

Theleastyouneedtoknowaboutregularexpressions
Ifyoudon'twanttofindoutexactlyhowregularexpressionswork,butjustwanttogetajobdone,youmight
findthesecommonexamplesuseful.Entertheminthe'Searchfor'box,andmakesurethatregularexpressions
areselected.
color|colourfindscolorandcolour
sep.ratefindssepthenanycharacterthenrateegseparate,seperate,andindeedsepXrate
sep[ae]ratefindsseparateandseperate[ae]meanseitheranaorane
changed?findschangeandchangedthedisoptionalbecauseitisfollowedbyaquestionmark
s\>findsthesattheendofaword
\<.findsthefirstletterofaword.
^.findsthefirstletterofaparagraph.
^$findsanemptyparagraph

HowregularexpressionsareappliedinOpenOffice.org
OpenOffice.orgregularexpressionsappeartodividethetexttobesearchedintoportionsandexamineeach
portionseparately.

https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

3/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

InWriter,textappearstobedividedintoparagraphs.Forexamplex.*zwillnotmatchxattheendofa
paragraphwithzbeginningthenextparagraph(x.*zmeansxthenanyornocharactersthenz).Paragraphs
seemtobetreatedseparately(althoughwediscusssomespecialcasesattheendofthisHowTo).

InadditionWriterconsiderseachtablecellandeachtextframeseparately.Textframesareexaminedafterall
theothertext/tablecellsonallpageshavebeenexamined.
IntheFind&Replacedialog,regularexpressionsmaybeusedintheSearchforbox.Ingeneraltheymaynot
beusedintheReplacewithbox.Theexceptionsarediscussedlater.

Literalcharacters
Ifyourregularexpressioncontainscharactersotherthanthesocalled'specialcharacters'.^$*+?\[({|
thenthosecharactersarematchedliterally.
Forexample:redmatchesredredrawandFreddie.
OpenOffice.orgallowsyoutochoosewhetheryoucareifacharacteris'UPPERCASE'or'lowercase'.Ifyou
ticktheboxto'matchcase'ontheFindandReplacedialog,thenredwillnotmatchRedorFREDifyouun
tickthatboxthenthecaseisignoredandbothwillbematched.

Specialcharacters
Thespecialcharactersare.^$*+?\[({|
Theyhavespecialmeaningsinaregularexpression,aswe'reabouttodescribe.
Ifyouwishtomatchoneofthesecharactersliterally,placeabackslash'\'beforeit.

https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

4/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

Forexample:tomatch$100use\$100the\$istakentomean$.

Singlecharactermatch.?
Thedot'.'specialcharacterstandsforanysinglecharacter(exceptnewline).
Forexample:r.dmatches'red'and'hotrod'and'bride'and'yourdog'
Thequestionmark'?'specialcharactermeans'matchzerooroneoftheprecedingcharacter'or'matchthe
precedingcharacterifitisfound'.
Forexample:rea?dmatches'red'and'read''a?'means'matchasingleaifthereisone'.
Specialcharacterscanbeusedincombinationwitheachother.Adotfollowedbyaquestionmarkmeans
'matchzerooroneofanysinglechacter'.
Forexample:star.?ingmatches'staring','starring','starting',and'starling',butnot'startling'

Repeatingmatch+*{m,n}
Theplus'+'specialcharactermeans'matchoneormoreoftheprecedingcharacter'.
Forexample:re+dmatches'red'and'reed'and'reeeeed'e+meansmatchoneormoree's.
Thestar'*'specialcharactermeans'matchzeroormoreoftheprecedingcharacter'.
Forexample:rea*dmatches'red'and'read'and'reaaaaaaad''a*'meansmatchzeroormorea's.
Acommonusefor'*'isafterthedotcharacterie'.*'whichmeans'anyornocharacters'.
Forexample:rea.*dmatches'read'and'reaXd'and'reaYYYYd'butnot'red'or'reXd'
Usethestar'*'withcautionitwillgrabeverythingitcan:
Forexample:'r.*d'matches'red'butinWriterifyourparagraphisactually'Therefereeshowedhimthered
cardagain'thematchfoundis'refereeshowedhimtheredcard'thatis,thefirst'r'andthelastpossible'd'.
Regularexpressionsaregreedybynature.

https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

5/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

Youmayspecifyhowmanytimesyouwishthematchtoberepeated,withcurlybrackets{}.Forexample
a{1,4}rgh!willmatchargh!,aargh!,aaargh!andaaaargh!inotherwordsbetween1and4a'sthenrgh!.
Alsonotethata{3}rgh!willmatchprecisely3a's,ieaaargh!,anda{2,}rgh!(withacomma)willmatchatleast
2a's,forexampleaargh!andaaaaaaaargh!.

Positionalmatch^$\<\>
Thecircumflex'^'specialcharactermeans'matchatthebeginningofthetext'.
Thedollar'$'specialcharactermeans'matchattheendofthetext'.
RememberthatOpenOffice.orgregularexpressionsdivideupthetexttobesearchedeachparagraphin
Writerisexaminedseparately.
Forexample:^redmatches'red'atthestartofaparagraph(rednightshepherd'sdelight).
Forexample:red$matches'red'attheendofaparagraph(hefelthimselfgored)
Forexample:^red$matchesinsideatablecellthatcontainsjust'red'
Inadditionahardlinebreak(enteredbyShiftEnter)isconsideredthebeginning/endoftext,andwillallowa^
or$match.
Thebackslash'\'specialcharactergivesspecialmeaningtothecharacterpairs'\<'and'\>',namely'matchat
thebeginningofaword',and'matchattheendofaword'
Forexample:\<redmatchesredatthebeginningofaword(shewentredderthanhedid).
Forexample:red\>matchesredattheendofaword(althoughneitherofthemcaredmuch.)
Thetestusedtodefinethebeginning/endofawordseemstobethattheprevious/nextcharacterisaspace,
underscore(_),tab,newline,paragraphmarkoranynonalphanumericcharacter.
Forexample:\<redmatches'person@rediton.com'
Forexample:red\>matches'Isaid,"Noonedared"'

Alternativematches|[...]
Thepipecharacter'|'isaspecialcharacterwhichallowstheexpressioneithersideofthe'|'tomatch.
Forexample:red|bluematches'red'and'blue'
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

6/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

Unfortunately,certainexpressionswhenusedafterapipearenotevaluated.Thisissofarknowntoaffect^
andbackreferences,andisthesubjectofissue46165(http://qa.openoffice.org/issues/show_bug.cgi?id=46165)
Forexample:^red|bluematchesparagraphsbeginningwith'red'andanyoccurrenceof'blue',butblue|^red
incorrectlymatchesonlyanyoccurrenceof'blue',failingtomatchparagraphsbeginningwith'red'
Theopensquarebracketscharacter[isaspecialcharacter.Charactersenclosedinsquarebracketsaretreated
asalternativesanyoneofthemmaymatch.Youcanalsoincluderangesofcharacters,suchasazor09,
ratherthantypinginabcdefghijklmnopqrstuvwxyzor0123456789
Forexample:r[eo]dmatches'red'and'rod'butnot'rid'
Forexample:[mp]utmatches'mut'and'nut'and'out'and'put'
Forexample:[hmp]utmatches'hut'and'mut'and'nut'and'out'and'put'
Specialcharacterswithinalternativematchsquarebracketsdonothavethesamespecialmeanings.Theonly
characterswhichdohavespecialmeaningsare],,^and\,andthemeaningsare:
]aclosingsquarebracketendsthealternativematchset[abcdef]
ahyphenindicatesarangeofcharacters,aswe'veseen,eg[09]
^ifthecaretisthefirstcharacterinthesquarebrackets,itnegatesthesearch.Forexample[^adxyz]
matchesanycharacterexceptabcdxyz.
\thebackslashisusedtoallow],,^and\tobeusedliterallyinsquarebrackets,andtoallow
hexadecimalcodes.Forexample,\]standsforaliteralclosingsquarebracket,so[[\]a]willmatchan
openingsquarebracket[,aclosingsquarebracket]orana.\\standsforaliteralbackslash.\x0009
standsforatabcharacter.
Justtoreemphasise:thesearethemeaningsofthesecharactersinsidesquarebrackets,andanyother
charactersaretreatedliterally.Forexample[\t]willmatcha't'oraspacenotataboraspace.Use[\x0009
]tomatchataboraspace.

POSIXbracketexpressions[:alpha:][:digit:]etc..
ThereismuchconfusionintheOpenOffice.orgcommunityaboutthese.TheHelpitselfisalsofarfromclear.
Thereareanumberof'POSIXbracketexpressions'(sometimescalled'POSIXcharacterclasses')availablein
OpenOffice.orgregularexpressions,oftheform[:classname:]whichallowamatchwithanyofthecharacters
inthatclass.Forinstance[:digit:]standsforanyofthedigits0123456789.
These(bydefinition)mayonlyappearinsidethesquarebracketsofanalternativematchsoavalidsyntax
wouldbe[abc[:digit:]],whichshouldmatcha,b,c,oranydigit09.Acorrectsyntaxtomatchjustanyone
digitwouldbe[[:digit:]].
Unfortunatelythisdoesnotworkasitshould!Thecorrectsyntaxdoesnotworkatall,butcurrentlyanincorrect
syntax([:digit:])willactuallymatchadigit,aslongasitisoutsidethesquarebracketsofanalternativematch.
(Obviouslythisisunsatisfactory,andisthesubjectofissue64368
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

7/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

(http://qa.openoffice.org/issues/show_bug.cgi?id=64368)).
ThePOSIXbracketexpressionsavailablearelistedbelow.Notethattheexactdefinitionofeachdependson
localeforexampleinadifferentlanguageothercharactersmaybeconsidered'alphabeticletters'in[:alpha:].
ThemeaningsgivenhereapplygenerallytoEnglishspeakinglocales(anddonottakeintoaccountanyUnicode
issues).
[:digit:]
standsforanyofthedigits0123456789.Thisisequivalentto09.
[:space:]
shouldstandforanywhitespacecharacter,includingtabhoweverascurrentlyimplementeditstands
simplyforaspacecharacter.NotethattheHelpiscurrentlymisleadinghere.(Thisisthesubjectof
issue41706(http://qa.openoffice.org/issues/show_bug.cgi?id=41706)).
[:print:]
shouldstandforanyprintablecharacterhoweverascurrentlyimplementeditdoesnotmatchthesingle
quotenorthedoublequotecharacters(andsomeotherssuchas).Itmatchesspace,butdoes
notmatchtab(thislatterisexpected/definedbehaviour).(Thisisthesubjectofissue83290
(http://qa.openoffice.org/issues/show_bug.cgi?id=83290)).
[:cntrl:]
standsforacontrolcharacter.Asfarasauserisconcerned,OpenOffice.orgdocumentshaveveryfew
controlcharacterstabandhard_line_breakarebothmatched,butparagraph_markisnot.
[:alpha:]
standsforaletter(includingaletterwithanaccent).Forexampleinthephrase(oftenusedinEnglish,and
heregivenwithaccentsasintheoriginallanguage)'djvu'all6letterswillmatch.
[:alnum:]
standsforacharacterthatsatisfieseither[:alpha:]or[:digit:]
[:lower:]
standsforalowercaseletter(includingaletterwithanaccent).Thecasematchingdoesnotworkunless
theMatchcaseboxistickedifthisboxisnottickedthisexpressionisequivalentto[:alpha:].
[:upper:]
standsforanuppercaseletter(includingaletterwithanaccent).Thecasematchingdoesnotworkunless
theMatchcaseboxistickedifthisboxisnottickedthisexpressionisequivalentto[:alpha:].
ThereseemstobelittleconsistencyinanyimplementationofPOSIXbracketexpressions(OOoorelsewhere).
Oneapproachissimplytousestraightforwardcharacterclassessoinsteadof[[:digit:]]youuse[09]for
example.

Grouping(...)andbackreferences\x$x
Roundbrackets()maybeusedtogroupterms.
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

8/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

Forexample:red(den)?willfind'red'and'redden'here(den)?means'oneorzeroofden'.
Forexample:(blue|black)birdwillfindboth'bluebird'and'blackbird'.
Eachgroupenclosedinroundbracketsisalsodefinedasareference,andcanbereferredtolaterinthesame
expressionusinga'backreference'.Inthe'Searchfor'box,backreferencesarewritten'\1','\2',etc.inthe
'Replacewith'boxtheyarewritten'$1','$2',etc.
'\1'or'$1'standsfor'whatevermatchedinthefirstroundbrackets''\2'or'$2'standsfor'whatevermatchedin
thesecondroundbrackets'andsoon.
Forexample:(blue|black)\1birdinthe'Searchfor'boxwillfindboth'bluebluebird'and'blackblackbird',
because'\1'standsforeitherblueorblack,whicheverwefound.Therefore'blackbluebird'doesnotmatch.
Backreferencesinthe'Replacewith'boxonlyworkfromOOo2.4onwards.Theuseof$1ratherthan\1
isconsistentwithperlsyntax,andmoreparticularlywiththeICUregexengine,whichmayatsometimereplace
theexistingOOoregexengine,thusresolvingmanyissues.
Forexample:(gr..n)(blu.)inthe'Searchfor'boxwillfind'greenblue'ifthe'Replacewith'boxhas$2$1the
replacementwillbe'bluegreen'.
Whenregularexpressionsareselected,toreplacetextwiththeliteralcharacter'$'youmustnowuse'\$'
similarlyfor'\'use'\\'.
Forexample:(1..)inthe'Searchfor'boxand\$$1inthe'Replacewith'boxreplaces'100'with'$100',and
'150'with'$150'.
$0inthe'Replacewith'boxreplaceswiththeentiretextfound.

Tabs,newlines,paragraphs\t\n$
Thecharacterpair'\t'hasspecialmeaningitstandsforatabcharacter.
Forexample:\tredwillmatchatabcharacterfollowedbytheword'red'.
InWriteranewlinemaybeenteredbypressingShiftEnter.Anewlinecharacteristherebyinsertedintothe
text,andthefollowingtextstartsonanewline.ThisisnotthesameasanewparagraphclickViewNon
printingcharacterstoseethedifference.
TheOOoregularexpressionbehaviourwhenmatchingparagraphmarksandnewlinecharactersis'unusual'.
Thisispartlybecauseregularexpressionsinothersoftwareusuallydealwithordinaryplaintext,whereasOOo
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

9/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

regularexpressionsdividethetextatparagraphmarks.Forwhateverreason,thisiswhatyoucando:

\nwillmatchanewline(ShiftEnter)ifitisenteredintheSearchbox.Inthiscontextitissimplytreated
likeacharacter,andcanbereplacedbysayaspace,ornothing.Theregularexpressionred\nwillmatch
redfollowedbyanewlinecharacterandifreplacedsimplybysaybluethenewlinewillalsobe
replaced.Theregularexpressionred$willmatch'red'whenitisfollowedbyanewline.Inthiscase,
replacingwith'blue'willonlyreplace'red'andwillleavethenewlineintact.
red\ngreenwillmatch'red'followedbyanewlinefollowedby'green'replacingwithsay'brown'will
removethenewline.Howeverneitherred.greennorred.*greenwillmatchherethedot.doesnot
matchnewline.
$onitsownwillmatchaparagraphmarkandcanbereplacedbysaya'space',orindeednothing,in
ordertomergetwoparagraphstogether.Notethatred$willmatch'red'attheendofaparagraph,andif
youreplaceitwithsayaspace,yousimplygetaspacewhere'red'wasandtheparagraphsare
unaffectedtheparagraphmarkisnotreplaced.Itmayhelptoregard$onitsownasaspecialsyntax,
uniquetoOOo.
^$willmatchanemptyparagraph,whichcanbereplacedbysaynothing,inordertoremovetheempty
paragraph.Notethat^red$matchesaparagraphwithonly'red'initreplacingthiswithnothingleaves
anemptyparagraphtheparagraphmarksateitherendarenotreplaced.Itmayhelptoregard^$onits
ownasaspecialsyntax,uniquetoOOo.Unfortunately,becauseOOohastakenoverthissyntax,it
seemsyoucannotuse^$tofindemptycellsinatable(noremptyCalccells).
Ifyouwishtoreplaceeverynewlinewithaparagraphmark,firstlyyouwillsearchfor\nwithFindAllto
selectthenewlines.ThenintheReplaceboxyouenter\n,whichintheReplaceboxstandsfora
paragraphmarkthenchooseReplace.Thisissomewhatbizarre,butatleastnowyouknow.Notethat\r
isinterpretedasaliteral'r',notacarriagereturn.
Toreplaceparagraphmarksasusedtogivelinesacertainlengthinsomehtmldocuments,forinstancewith
"normal"automaticallywrappedlinesandparagraphs,thefollowing3stepsshouldhelp.Don'tforgettochoose
MoreOptionsandticktheRegularExpressionsboxforthisprocedure.
1.Soasnottolose"normal"paragraphmarksattheendof"normal"paragraphs,replacetwoconsecutive
paragraphmarksusingasequenceofcharactersnotoccurringanywhereelseinthetext,like"*****"toreplace
anemptyparagraphthismakesiteasytofindandreinstatelater.Youdothisbyputting^$intheFindboxand
"*****"intheReplacebox.(Ifyou'reonlydealingwithalimitedchunkoftext,don'tforgettocheck"current
selectiononly"under"moreoptions"intheFindandReplacebox.)
2.Searchfortheremaininglineendparagraphmarksbyputting$intheFindbox.Toreplacethemarkwitha
"space"justtypeaspaceintheReplacedialogue.
3.Nowthatthetextisreadyfornormallinewrapping,putbackthe"normal"paragraphmarksbytyping
"*****"intheFindboxand\nintheReplacebox.(Remembertocheck"currentselectiononly"where
appropriate!)
Beforeyoutrythis,createatestdocumenttopractiseon.
Thisisagoodsequencetomakeintoamacro.YoucanfindmacrosuggestionsonthisOOoforumpage:
"replacinghardparagraphs"(http://www.oooforum.org/forum/viewtopic.phtml?t=3641).
(Thisprocedurealsohelpsdealindirectlywithlinebreakproblems.)
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

10/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

Hexadecimalcodes\xXXXX
Thecharactersequence'\xthena4digithexadecimalnumber'standsforthecharacterwiththatcode.
Forexample:\x002Astandsforthestarcharacter'*'.
Hexadecimalcodescanbeseenonthe'InsertSpecialCharacter'dialog.

The'Replacewith'box\t\n&$1$2
Usersaresometimesconfusedwithwhatcanbedoneusingthe'Replacewith'boxinaFind&Replacedialog.
Ingeneral,regularexpressionsdonotworkinthe'Replacewith'box.Thecharactersyoutypereplacethe
foundtextliterally.
Thefourconstructsthatdoworkare:
\tinsertsatab,replacingthetextfound.
\ninsertsaparagraphmark,replacingthetextfound.Thismaybeunexpected,because\ninthe'Search
for'boxmeans'newline'!Insomeoperatingsystemsitispossibletouseunicodeinputtodirectlytypea
newlinecharacter(U+000A)inthe'Replacewith'box,providingaworkaround,butthisisnotuniversal.
$1,$2,etcarebackreferences,which(fromOOo2.4)inserttextgroupsfound.SeeunderGroupingand
backreferences.$0insertstheentiretextfound.
&alsoinsertstheentiretextfound.
Forexampleifyousearchedforbird|berry,youwouldwouldfindeither'bird'or'berry'nowtoreplacewith
black&wouldgiveyoueither'blackbird'or'blackberry'.

TroubleshootingOOoregularexpressions
Ifyouarenewtoregularexpressions,pleaserealisethattheycanbetrickyifyouarenotgettingtheresultsyou
expect,youmightneedtocheckthatyouunderstandwellenough.Trytokeepregularexpressionsassimple
andunambitiousaspossible.
HerearesomefurtherpointsofinterestwithOOoregularexpressions:
Ifyoufindanunexpectedbehaviour,pleasecheckintherelevantsectioninthisHowTomanyofthe
behaviourissueshavebeendocumentedhere.
Regularexpressionsare'greedy'thatistheywillmatchasmuchtextastheycan.Considerusingcurly
andsquarebracketsforexample[^]{1,5}\>matches1to5nonspacecharactersattheendofa
word.
PleasebecarefulwhenusingtheReplaceAllbutton.Thereareafewrareoccasionswhenthiswillgive
unexpectedresults.Forexampletoremovethefirstcharacterofeveryparagraphyoumight'Searchfor'
^.and'Replacewith'nothingclicking'ReplaceAll'nowwillwipeout*all*yourtext,insteadofjustthe
firstcharacterofeachparagraph.Issue82473(http://qa.openoffice.org/issues/show_bug.cgi?id=82473)
discussesthis.Theworkaroundisto'FindAll',then'Replace'perhapsthesafestwayisnottousethe
'ReplaceAll'buttonatallwithregularexpressions.
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

11/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

TipsandTricks
Herearesomeexamplesthatmaybeuseful:
\<([^ ]+)[ ]+\1

findsduplicatewordsseparatedbyspaces(notethatthereisaspacebeforeeach])
\<[:alpha:]*\>

findsanywordinthewholedocument(notice:thecheckboxregularexpressionmustbycheckt)
\<[1-9][0-9]*\>

findsdecimalnumbers
\<0[0-7]*\>

findsoctal(base8)numbers
\<0x[A-Fa-f0-9]+\>

findshexadecimal(base16)numbers
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-z]{2,6}

findsmostemailaddresses(thereisnoperfectregularexpressionthisisapracticalsolution)
SeeAlso
TheICUregularexpressionpackage(http://www.icuproject.org/userguide/regexp.html),acandidateto
replacetheexistingOOoregularexpressionengine(see:Regexp).
Exampleregularexpressions(http://www.OOoNinja.com/2007/12/exampleregularexpressionsfor
writer.html)(OpenOffice.orgNinja)
Backreferencesinsubstitutions(http://www.OOoNinja.com/2007/12/backreferencesinreplacements
new.html)(OpenOffice.orgNinja)
GuidetoregularexpressionsinOpenOffice.org(http://www.oooninja.com/2007/12/powerfultext
matchingwithregular.html)(OpenOffice.orgNinja)
Searchingandreplacingparagraphreturns(carriagereturns),tabs,andotherspecialcharacters
(http://openoffice.blogs.com/openoffice/2009/11/searchingandreplacingparagraphreturnscarriage
returnstabsandotherspecialcharactersinopen.html)(SolveigHaugland'sblog)
Obtenidodehttps://wiki.openoffice.org/w/index.php?
title=Documentation/How_Tos/Regular_Expressions_in_Writer&oldid=153756
Categoras: Documentation/Reference Documentation/HowTos/Writer
Estapginafuemodificadaporltimavezel23dic2009,alas22:14.
ContentisavailableunderALv2unlessotherwisenoted.
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

12/13

27/10/2014

Documentation/How Tos/Regular Expressions in Writer - Apache OpenOffice Wiki

https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

13/13

Anda mungkin juga menyukai