The Royal Nick Humphrey Global World IT Forum, Home Edition  

Go Back   The Royal Nick Humphrey Global World IT Forum, Home Edition > Programmering Forum > Programmering generelt > Regex Forum
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-06, 01:42
Nickleus's Avatar
Nickleus Nickleus is offline
Nick Humphrey - Admin
 
Join Date: 06 Apr 2004
Location: Noreg
Posts: 2,794
Send a message via MSN to Nickleus Send a message via Skype™ to Nickleus
Default Regexp eksempler

her er hvordan man fjerner alle linjer som ikke begynner med strengen IPA:
finn:
^[^IPA].*$

erstatt med:
ingenting


Relevante engelske ord er how to replace all lines that do not, don't begin, not beginning with, find, search, replace with nothing.
__________________
Nick Humphrey
Download for free my experimental music, art, poetry and pictures.
My album Classic E B-sides can be purchased on both itunes and amazon.com.
Help me improve my phrasebook of world languages.
I offer remote healing services.
My blog.
Reply With Quote
  #2  
Old 01-02-07, 15:52
Nickleus's Avatar
Nickleus Nickleus is offline
Nick Humphrey - Admin
 
Join Date: 06 Apr 2004
Location: Noreg
Posts: 2,794
Send a message via MSN to Nickleus Send a message via Skype™ to Nickleus
Default regex - hvordan erstatte alle verdier til xml xslt xsl-fo html attributt

jeg fikk et problem da jeg gjorde om på formuleringen av en xslt/xsl-fo fil i dag. jeg først hadde plassert alle elementer med faste top (og left/right) verdier, men så fant jeg ut at jeg måtte dele siden inn i 3 forskjellige deler:
fo:static-content (<-- xsl-region-before)
fo:static-content (<-- xsl-region-after)
fo:flow (<-- xsl-region-body)

så alle top verdier til den nedre delen av page-en min plutselig var blitt 175mm for store. siden jeg ikke fant ut hvordan man søker og erstatter med regex for å trekke fra en gitt sum fra en tall-verdi, matematisk, måtte jeg lage/definere en xsl variable, bodymargin, rett etter xsl:stylesheet taggen, slik:
Code:
<xsl:variable name="bodymargin" select="175"/>
og så plugge den inn i hvert top attributt, slik at jeg fikk dette (før/etter):
før:
Code:
top="186mm"
etter:
Code:
top="{186 - $bodymargin}mm"
istedenfor å gå gjennom over 500 linjer med kode manuelt og trekke fra verdien for hånd, lagde jeg en regexp som gjorde dette for meg (med hjelp av xsl-variable-en:
find what:
\ top="\([0-9]*\.*[0-9]*\)mm"

replace with:
\ top="{\1 - \$bodymargin}mm"

jeg skrev \ top istedenfor bare top fordi jeg fant ut at jeg også hadde noen tilfeller med margin-top så da ble ting feil uten mellomrom foran.

\([0-9]*\.*[0-9]*\) lagrer tall-verdien i en midlertidig backreference, \1, så vi kan plugge det tilbake inn i "regnestykket" i replace-setningen.

{\1 - \$bodymargin} klammene er xslt syntaks for å gjøre en matematisk beregning. \1 er som sagt, verdien vi har tatt vare på fra søkestrengen, så skal vi trekke fra den verdien, verdien til bodymargin variabelen. i xslt, som i f.eks. bash, php, osv, må man ha dollar-tegnet foran variabelen for å få tak i verdien og her har jeg en skråstrek \ foran den (\$) fordi $ er et reservert tegn i regex.

Relevante engelske ord er how to substitute, replace values of an xml, html attribute and subtract a number value from their value using an xsl, xslt variable and regular expressions, back reference, references, backreferences, curly bracket, brackets, brace, braces, parenthesis, parentheses.
__________________
Nick Humphrey
Download for free my experimental music, art, poetry and pictures.
My album Classic E B-sides can be purchased on both itunes and amazon.com.
Help me improve my phrasebook of world languages.
I offer remote healing services.
My blog.

Last edited by Nickleus : 01-02-07 at 15:55.
Reply With Quote
  #3  
Old 29-05-10, 13:24
Nickleus's Avatar
Nickleus Nickleus is offline
Nick Humphrey - Admin
 
Join Date: 06 Apr 2004
Location: Noreg
Posts: 2,794
Send a message via MSN to Nickleus Send a message via Skype™ to Nickleus
Default Regexp eksempler - merging to title attributes in two different html tags

how to transform this:
Quote:
<td title="Noble gases;Primordial;Gas" style="text-align:center;color:red;background-color:rgb(192, 255, 255);border:1px solid purple;"><a href="http://en.wikipedia.org/wiki/Helium" title="Helium (He) 2">He</a></td>
into this:
Quote:
<td style="text-align:center;color:red;background-color:rgb(192, 255, 255);border:1px solid purple;"><a href="http://en.wikipedia.org/wiki/Helium" title="Helium (He) 2: Noble gases;Primordial;Gas"></a></td>
search for:
Code:
<td title="(.+)" (style.+)">[A-Z][a-z]*
replace with:
Code:
<td \2: \1">&nbsp;
__________________
Nick Humphrey
Download for free my experimental music, art, poetry and pictures.
My album Classic E B-sides can be purchased on both itunes and amazon.com.
Help me improve my phrasebook of world languages.
I offer remote healing services.
My blog.
Reply With Quote
  #4  
Old 29-05-10, 13:39
Nickleus's Avatar
Nickleus Nickleus is offline
Nick Humphrey - Admin
 
Join Date: 06 Apr 2004
Location: Noreg
Posts: 2,794
Send a message via MSN to Nickleus Send a message via Skype™ to Nickleus
Default Regexp eksempler - replace html tag innerhtml text with attribute value

here's how to turn this:
Quote:
<td style="text-align:center;color:black;background-color:rgb(255, 191, 255);border:1px solid purple;"><a href="http://en.wikipedia.org/wiki/Lanthanum" title="Lanthanum (La) 57: Lanthanoids;Primordial;Solid">La</a></td>
into this:
Quote:
<td style="text-align:center;color:black;background-color:rgb(255, 191, 255);border:1px solid purple;"><a href="http://en.wikipedia.org/wiki/Lanthanum" title="Lanthanum (La) : Lanthanoids;Primordial;Solid">57</a></td>
search for:
Code:
\) ([0-9]+)(:.*">)[A-Z][a-z]*
replace with:
Code:
) \2\1
__________________
Nick Humphrey
Download for free my experimental music, art, poetry and pictures.
My album Classic E B-sides can be purchased on both itunes and amazon.com.
Help me improve my phrasebook of world languages.
I offer remote healing services.
My blog.
Reply With Quote
  #5  
Old 29-05-10, 21:32
Nickleus's Avatar
Nickleus Nickleus is offline
Nick Humphrey - Admin
 
Join Date: 06 Apr 2004
Location: Noreg
Posts: 2,794
Send a message via MSN to Nickleus Send a message via Skype™ to Nickleus
Default Regexp eksempler - replace css values with parts of class name

all the css values are identical so were going to use regex to insert the correct values into the css values, taken from parts of the class name.
so we're going to turn this:
Quote:
.black160255160purple {text-align:center;color:black;background-color:rgb(160, 255, 160);border:1px solid purple;}
.black255102102orange {text-align:center;color:black;background-color:rgb(160, 255, 160);border:1px solid purple;}
.black255153204blue {text-align:center;color:black;background-color:rgb(160, 255, 160);border:1px solid purple;}
into this:
Quote:
.black160255160purple {text-align:center;color:black;background-color:rgb(160, 255, 160);border:1px solid purple;}
.black255102102orange {text-align:center;color:black;background-color:rgb(255, 102, 102);border:1px solid orange;}
.black255153204blue {text-align:center;color:black;background-color:rgb(255, 153, 204);border:1px solid blue;}
search for:
Code:
^\.([A-Za-z]+)([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9][0-9][0-9])([A-Za-z]+)( .+)black(.+\()[0-9][0-9][0-9].+[0-9][0-9](\).+solid )purple
replace with:
Code:
.\1\2\3\4\5\6\1\7\2, \3, \4\8\5
__________________
Nick Humphrey
Download for free my experimental music, art, poetry and pictures.
My album Classic E B-sides can be purchased on both itunes and amazon.com.
Help me improve my phrasebook of world languages.
I offer remote healing services.
My blog.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Hello World Collection - hello world eksempler i mange forskjellige språk Nickleus Programmering generelt 0 23-03-06 12:02
Versjon og versjoner - eksempler av hvordan man implementerer versjonering Nickleus Programmering generelt 0 22-02-06 15:59
Hvordan finne alle jsp html text tagger uten maxlength mha regexp Nickleus Regex Forum 0 02-02-06 13:24
HTML form validering med Javascript og regexp Nickleus Regex Forum 1 01-02-06 10:37
Javascript og regexp tutorial Nickleus Javascript Forum 1 05-12-05 14:44


All times are GMT +2. The time now is 10:33.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Check out my phrasebook
All rights reserved 2004-2009