Can this regex be implemented in Pharo's one?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Can this regex be implemented in Pharo's one?

Mariano Martinez Peck
Hi guys,

I have this Javascript regex to prefix CSS rules to a given ID:

css = css.replace(/([,|\}][\s$]*)([\.#]?-?[_a-zA-Z]+[_a-zA-Z0-9-]*)/g,  "$1" + "#myDiv" + " $2");

I am trying to make this work on Pharo (and then I will need in GemStone) but I am getting errors while trying to create the regex itself. I am very far from being a regex expert (I got that regex from StackOverflow). Any help is appreciated.

Cheers,

--
Reply | Threaded
Open this post in threaded view
|

Re: Can this regex be implemented in Pharo's one?

Max Leske

On 22 May 2017, at 20:50, Mariano Martinez Peck <[hidden email]> wrote:

Hi guys,

I have this Javascript regex to prefix CSS rules to a given ID:

css = css.replace(/([,|\}][\s$]*)([\.#]?-?[_a-zA-Z]+[_a-zA-Z0-9-]*)/g,  "$1" + "#myDiv" + " $2”);

/([,|}][\s$]*)([.#]?-?[_a-zA-Z]+[_a-zA-Z0-9\-]*)


HTH,
Max


I am trying to make this work on Pharo (and then I will need in GemStone) but I am getting errors while trying to create the regex itself. I am very far from being a regex expert (I got that regex from StackOverflow). Any help is appreciated.

Cheers,

--

Reply | Threaded
Open this post in threaded view
|

Re: Can this regex be implemented in Pharo's one?

Mariano Martinez Peck


On Mon, May 22, 2017 at 4:30 PM, Max Leske <[hidden email]> wrote:

On 22 May 2017, at 20:50, Mariano Martinez Peck <[hidden email]> wrote:

Hi guys,

I have this Javascript regex to prefix CSS rules to a given ID:

css = css.replace(/([,|\}][\s$]*)([\.#]?-?[_a-zA-Z]+[_a-zA-Z0-9-]*)/g,  "$1" + "#myDiv" + " $2”);

/([,|}][\s$]*)([.#]?-?[_a-zA-Z]+[_a-zA-Z0-9\-]*)

Thanks Max,

That allows me to create the regex correctly (well at least it doesn't fail). But how can I now make the translate, for  example, from this input:

' .aClass { color: red ; } ' 

to 

'#myDiv .aClass {  color: red; }' 



Thanks!
 


HTH,
Max


I am trying to make this work on Pharo (and then I will need in GemStone) but I am getting errors while trying to create the regex itself. I am very far from being a regex expert (I got that regex from StackOverflow). Any help is appreciated.

Cheers,

--




--
Reply | Threaded
Open this post in threaded view
|

Re: Can this regex be implemented in Pharo's one?

Max Leske

On 22 May 2017, at 22:30, Mariano Martinez Peck <[hidden email]> wrote:



On Mon, May 22, 2017 at 4:30 PM, Max Leske <[hidden email]> wrote:

On 22 May 2017, at 20:50, Mariano Martinez Peck <[hidden email]> wrote:

Hi guys,

I have this Javascript regex to prefix CSS rules to a given ID:

css = css.replace(/([,|\}][\s$]*)([\.#]?-?[_a-zA-Z]+[_a-zA-Z0-9-]*)/g,  "$1" + "#myDiv" + " $2”);

/([,|}][\s$]*)([.#]?-?[_a-zA-Z]+[_a-zA-Z0-9\-]*)

Thanks Max,

That allows me to create the regex correctly (well at least it doesn't fail). But how can I now make the translate, for  example, from this input:

' .aClass { color: red ; } ' 

to 

'#myDiv .aClass {  color: red; }' 

That's a bit more work in Pharo, unfortunately. You'll have to access capture groups explicitly:

matcher := '(\d)(\d_\d)' asRegex.
matcher matches: '12_3'.

matcher subexpression: 1. "'12_3'"
matcher subexpression: 2. "'1'"
matcher subexpression: 3 "'2_3'"

Max




Thanks!
 


HTH,
Max


I am trying to make this work on Pharo (and then I will need in GemStone) but I am getting errors while trying to create the regex itself. I am very far from being a regex expert (I got that regex from StackOverflow). Any help is appreciated.

Cheers,

-- 




--