RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

enderNafi
Hi all,


I’m a little embarrassed to ask this question for two reasons:
1. I should have known sufficient regex, every coder should.
2. I should have found the answer online, every coder should.

But apparently I couldn’t and I’m struggling for quite a time; please, excuse my ignorance.

I need a RegEx for the below substitution;
Input:
(everybody-should-know-this and this”/‘
Output:
everybody-should-know-this and this

The statement should clear all whitespaces and non-ascii chars except dash and space.
Here is my current code:

_replace space with “nqpSPACEqpn” in tParams
_replace “-“ with “nqpDASHqpn” in tParams
_put replaceText(tParams, “\W”, “”) into tParams
_replace “nqpSPACEqpn” with space in tParams
_replace “ nqpDASHqpn” with “-" in tParams

I’m sure it can be done with a single line of code something like
_put replaceText(tParams, “*** regEx excluding space and dash here ***”, “”) into tParams


Thanks for any help…


Best,

~ Ender
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_________________________________________

Mac OS X 10.9.1 • LiveCode 6.5.1 & xCode 5.0.1
Reply | Threaded
Open this post in threaded view
|

Re: RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

Thierry Douez
2014-01-29 Ender Nafi Elekcioglu <[hidden email]>:

> The statement should clear all whitespaces and non-ascii chars except dash and space.
>
> ~ Ender


[ ...]  -> character class; match any characters in between the brackets
[^...] -> character class; do *NOT* match all characters in between the brackets

So, you can try something like:

put replacetext( mytext, "[^a-zA-Z0-9]", empty) into mytext

a-z  -> any chars from a to z
A-Z  -> any chars from A to Z

Still missing the dash; add it inside the brackets:

put replacetext( mytext, "[^a-zA-Z0-9-]", empty) into mytext

and carry on adding extra chars until you are happy.

Does that makes sense?


Thierry

------------------------------------------------
Thierry Douez - http://sunny-tdz.com
Maker of sunnYperl - sunnYmidi - sunnYmage - sunnYpdf

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

John Craig-4
In reply to this post by enderNafi
When you say 'non-ascii' do you mean non alphanumeric?

if tData contains your string then..
put replaceText(tData, "[^[:alnum:]- ]", "")

will replace anything that isn't alphanumeric, dash or space with blnk.

:)



On 29/01/2014 15:00, Ender Nafi Elekcioglu wrote:

> Hi all,
>
>
> I’m a little embarrassed to ask this question for two reasons:
> 1. I should have known sufficient regex, every coder should.
> 2. I should have found the answer online, every coder should.
>
> But apparently I couldn’t and I’m struggling for quite a time; please, excuse my ignorance.
>
> I need a RegEx for the below substitution;
> Input:
> (everybody-should-know-this and this”/‘
> Output:
> everybody-should-know-this and this
>
> The statement should clear all whitespaces and non-ascii chars except dash and space.
> Here is my current code:
>
> _replace space with “nqpSPACEqpn” in tParams
> _replace “-“ with “nqpDASHqpn” in tParams
> _put replaceText(tParams, “\W”, “”) into tParams
> _replace “nqpSPACEqpn” with space in tParams
> _replace “ nqpDASHqpn” with “-" in tParams
>
> I’m sure it can be done with a single line of code something like
> _put replaceText(tParams, “*** regEx excluding space and dash here ***”, “”) into tParams
>
>
> Thanks for any help…
>
>
> Best,
>
> ~ Ender
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

enderNafi
Thierry, John;

Thank you very much,
both work just fine.

Inspecting your solutions, I’ve found my stupid mistake, btw.
This was what I was trying:
“[^\W- ]”
which should be obviously
“[^\w- ]”

Silly me :)


Thanks again…

Best,

~ Ender
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_________________________________________

Mac OS X 10.9.1 • LiveCode 6.5.1 & xCode 5.0.1
Reply | Threaded
Open this post in threaded view
|

Re: RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

Richmond Mathewson-2
In reply to this post by Thierry Douez
On 29/01/14 17:43, Thierry Douez wrote:

> 2014-01-29 Ender Nafi Elekcioglu <[hidden email]>:
>
>> The statement should clear all whitespaces and non-ascii chars except dash and space.
>>
>> ~ Ender
>
> [ ...]  -> character class; match any characters in between the brackets
> [^...] -> character class; do *NOT* match all characters in between the brackets
>
> So, you can try something like:
>
> put replacetext( mytext, "[^a-zA-Z0-9]", empty) into mytext
>
> a-z  -> any chars from a to z
> A-Z  -> any chars from A to Z
>
> Still missing the dash; add it inside the brackets:
>
> put replacetext( mytext, "[^a-zA-Z0-9-]", empty) into mytext
>
> and carry on adding extra chars until you are happy.
>
> Does that makes sense?
>
>
> Thierry
>
>

Wait a minute . .  .

This is to remove Non-Ascii chars: but what goes on above looks as
though it is meant to remove more than that.

Richmond.

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Resize Stack Differences on Mac and Windows

Ray Horsley-2
In reply to this post by Thierry Douez
I'm not sure how many versions back this goes but apparently the
following script works differently on a Mac and Windows with 6.5.2:

    on resizeStack
       put the ticks
    end resizeStack

On Windows the message is sent continually as long as the mouse is down
and I'm resizing the stack.  On a Mac the resizeStack message is sent
just once when I let the mouse up after resizing the stack.

Does anybody have any experience with this anomaly?

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Resize Stack Differences on Mac and Windows

Richmond Mathewson-2
On 29/01/14 18:29, Ray wrote:

> I'm not sure how many versions back this goes but apparently the
> following script works differently on a Mac and Windows with 6.5.2:
>
>    on resizeStack
>       put the ticks
>    end resizeStack
>
> On Windows the message is sent continually as long as the mouse is
> down and I'm resizing the stack.  On a Mac the resizeStack message is
> sent just once when I let the mouse up after resizing the stack.
>
> Does anybody have any experience with this anomaly?

Dunno; on Linux (!!!!!!!!!) it is sent continuously, or rather (to be
accurate), repeatedly.

But; what exactly is the point of this script in the first place?

Richmond.

>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Resize Stack Differences on Mac and Windows

Jan Schenkel
In reply to this post by Ray Horsley-2
Hi Ray,

It depends on the 'liveResizing' property of the stack.
The calculations needed to resize the content of the stack can be time-consuming.
And on Mac redrawing the window takes longer than on WIndows/Unix.

So the default behaviour on Mac is not to send 'resizeStack' messages unless you specifically turn 'liveResizing' on.

HTH,

Jan Schenkel.

=====
Quartam Reports & PDF Library for LiveCode
www.quartam.com

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

--------------------------------------------
On Wed, 1/29/14, Ray <[hidden email]> wrote:

 Subject: Resize Stack Differences on Mac and Windows
 To: [hidden email]
 Date: Wednesday, January 29, 2014, 8:29 AM
 
 I'm not sure how many versions back
 this goes but apparently the following script works
 differently on a Mac and Windows with 6.5.2:
 
    on resizeStack
       put the ticks
    end resizeStack
 
 On Windows the message is sent continually as long as the
 mouse is down and I'm resizing the stack.  On a Mac the
 resizeStack message is sent just once when I let the mouse
 up after resizing the stack.
 
 Does anybody have any experience with this anomaly?
 
 _______________________________________________
 use-livecode mailing list
 [hidden email]
 Please visit this url to subscribe, unsubscribe and manage
 your subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Resize Stack Differences on Mac and Windows

Richmond Mathewson-2
In reply to this post by Richmond Mathewson-2
On 29/01/14 18:32, Richmond wrote:

> On 29/01/14 18:29, Ray wrote:
>> I'm not sure how many versions back this goes but apparently the
>> following script works differently on a Mac and Windows with 6.5.2:
>>
>>    on resizeStack
>>       put the ticks
>>    end resizeStack
>>
>> On Windows the message is sent continually as long as the mouse is
>> down and I'm resizing the stack.  On a Mac the resizeStack message is
>> sent just once when I let the mouse up after resizing the stack.
>>
>> Does anybody have any experience with this anomaly?
>
> Dunno; on Linux (!!!!!!!!!) it is sent continuously, or rather (to be
> accurate), repeatedly.
>
> But; what exactly is the point of this script in the first place?
>
> Richmond.
>

Here's something a whole lot more useful:

on resizeStack
    put (the width of me) & "," & (the height of me)
end resizeStack


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Resize Stack Differences on Mac and Windows

Paul Hibbert
In reply to this post by Ray Horsley-2
I suspect this is a platform issue that RR can't easily overcome, the dictionary states;

On Mac OS X systems…
…The stack's original width and height are passed only with the first resizeStack message sent during a resize operation.

So I'd guess the Mac OS is blocking the operation during the resize.

Paul


On 2014-01-29, at 8:29 AM, Ray <[hidden email]> wrote:

> I'm not sure how many versions back this goes but apparently the following script works differently on a Mac and Windows with 6.5.2:
>
>   on resizeStack
>      put the ticks
>   end resizeStack
>
> On Windows the message is sent continually as long as the mouse is down and I'm resizing the stack.  On a Mac the resizeStack message is sent just once when I let the mouse up after resizing the stack.
>
> Does anybody have any experience with this anomaly?
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

John Craig-4
In reply to this post by enderNafi
( Just remember that \w will include certain punctuation  ;)  )


On 29/01/2014 16:25, Ender Nafi Elekcioglu wrote:

> Thierry, John;
>
> Thank you very much,
> both work just fine.
>
> Inspecting your solutions, I’ve found my stupid mistake, btw.
> This was what I was trying:
> “[^\W- ]”
> which should be obviously
> “[^\w- ]”
>
> Silly me :)
>
>
> Thanks again…
>
> Best,
>
> ~ Ender
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

enderNafi
In reply to this post by Richmond Mathewson-2
Richmond,

My subject line is confusing.
What I meant was “removing all non-alphanumeric chars except dash and space”
*Non-Ascii* was just a wrong statement.

Thierry and John’s solutions work fine.


Best,

~ Ender


From: Richmond Richmond
Reply: Richmond [hidden email]
Date: January 29, 2014 at 18:26:36
To: How to use LiveCode [hidden email]
Subject:  Re: RegEx for Removing Non-Ascii Chars Except Certain Whitespaces 


Wait a minute . . . 

This is to remove Non-Ascii chars: but what goes on above looks as 
though it is meant to remove more than that. 

Richmond. 

_______________________________________________ 
use-livecode mailing list 
[hidden email] 
Please visit this url to subscribe, unsubscribe and manage your subscription preferences: 
http://lists.runrev.com/mailman/listinfo/use-livecode 
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_________________________________________

Mac OS X 10.9.1 • LiveCode 6.5.1 & xCode 5.0.1
Reply | Threaded
Open this post in threaded view
|

Re: RegEx for Removing Non-Ascii Chars Except Certain Whitespaces

Thierry Douez
2014-01-29 Ender Nafi Elekcioglu <[hidden email]>:
> Richmond,
>
> My subject line is confusing.
> What I meant was “removing all non-alphanumeric chars except dash and space”
> *Non-Ascii* was just a wrong statement.
>
> Thierry and John’s solutions work fine.

In fact, they are the same :)

I choosed the "extended" form and
I personaly don't use much the [:xxx:] syntax.

Thierry



------------------------------------------------
Thierry Douez - http://sunny-tdz.com
Maker of sunnYperl - sunnYmidi - sunnYmage - sunnYpdf

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Resize Stack Differences on Mac and Windows

Richard Gaskin
In reply to this post by Jan Schenkel
Jan Schenkel wrote:
> It depends on the 'liveResizing' property of the stack.
> The calculations needed to resize the content of the stack can be time-consuming.
> And on Mac redrawing the window takes longer than on WIndows/Unix.
>
> So the default behaviour on Mac is not to send 'resizeStack' messages unless you specifically turn 'liveResizing' on.

Given that live resizing has been the default on Mac since OS X, to help
our apps look more like other apps I submitted a request some time ago
to make liveResizing on by default:

http://quality.runrev.com/show_bug.cgi?id=5331

--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  Follow me on Twitter:  http://twitter.com/FourthWorldSys

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Resize Stack Differences on Mac and Windows

Ray Horsley-2
In reply to this post by Richmond Mathewson-2
Richard - I have a stack of 'user preferences' which shows the width and
height of another stack as it's resized.  These numbers which should
auto update continuously as the user continues to hold the mouse down
and resize the stack, so unfortunately your suggestion won't work.

However, setting the liveResizing property to true as Jan Schenkel
suggested makes everything work on the Mac just as it does on Windows.  
Thanks Jan!  An interesting thing about the liveResizing property is
that it does not get saved with the stack.  Also, setting the
decorations of the stack resets the liveResizing property to false for
some reason.

Anyway, its fixed.

Oh, and thanks for requesting this be cleaned up Richard.

Thanks,

Ray
LinkIt! Software

On 1/29/2014 11:35 AM, Richmond wrote:

> On 29/01/14 18:32, Richmond wrote:
>> On 29/01/14 18:29, Ray wrote:
>>> I'm not sure how many versions back this goes but apparently the
>>> following script works differently on a Mac and Windows with 6.5.2:
>>>
>>>    on resizeStack
>>>       put the ticks
>>>    end resizeStack
>>>
>>> On Windows the message is sent continually as long as the mouse is
>>> down and I'm resizing the stack.  On a Mac the resizeStack message
>>> is sent just once when I let the mouse up after resizing the stack.
>>>
>>> Does anybody have any experience with this anomaly?
>>
>> Dunno; on Linux (!!!!!!!!!) it is sent continuously, or rather (to be
>> accurate), repeatedly.
>>
>> But; what exactly is the point of this script in the first place?
>>
>> Richmond.
>>
>
> Here's something a whole lot more useful:
>
> on resizeStack
>    put (the width of me) & "," & (the height of me)
> end resizeStack
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode