Sponsored Content
Top Forums Shell Programming and Scripting How to test that a string doesn't contain specific characters? Post 302984424 by Arnaudh78 on Tuesday 25th of October 2016 06:25:11 PM
Old 10-25-2016
Quote:
Originally Posted by disedorgue
Hi,
Your regex in first post could work with correct locale, example:
Code:
$ XX="יאח"
$ LC_ALL=C
$ [[ "$XX" =~ [A-Za-z0-9_] ]] && echo ok
$ LC_ALL=fr_FR.UTF-8
$ [[ "$XX" =~ [A-Za-z0-9_] ]] && echo ok
ok

I choice "fr_FR.UTF-8" because I'm french Smilie

Regards.
Quote:
Originally Posted by disedorgue
In your case, you must set LC_ALL=C because you want exclude characters with accent.

Regards.
Oh ok, I understand,merci, Thanks it works ! SmilieSmilie

Last edited by Arnaudh78; 10-25-2016 at 07:31 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing specific characters in a string

Hi Friends, Following is an output of a script OPWQERIUTYKLSADFJHGXZNMCVBWQOPERIUTYKLSADFJHGXZNMCVB I want to replace above string's 11 to 17 character by ******* (7 stars) How can it be done? Please somebody guide me. (6 Replies)
Discussion started by: anushree.a
6 Replies

2. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

3. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

4. Programming

Kernel module - How to test if file doesn't exist

Hey, I'm currently getting into some kernel module progamming. As a little exercise I want to read the headers out of an ELF file. My code is very simple, here is the important part: struct file *fp; /* ... */ fp = filp_open("some/file/on/my/pc", O_RDONLY, 0); if(fp == NULL) { ... (15 Replies)
Discussion started by: disaster
15 Replies

5. Shell Programming and Scripting

Value of variable is NULL, but test doesn't seem to recognize

Hello, Unix-forums! My problem: read -p "Enter any number, please" number sleep 1 echo $number | tr -d 0-9 test -z $number && echo "Thank you" || echo "This is not a number"Test always displays "This is not a number". It doesn't matter if I entered a or 1. But if I order echo... (2 Replies)
Discussion started by: intelinside
2 Replies

6. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

7. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

8. Shell Programming and Scripting

Count specific characters at specific column positions

Hi all, I need help. I have an input text file (input.txt) like this: 21 GTGCAACACCGTCTTGAGAGG 50 21 GACCGAGACAGAATGAAAATC 73 21 CGGGTCTGTAGTAGCAAACGC 108 21 CGAAAAATGAACCCCTTTATC 220 21 CGTGATCCTGTTGAAGGGTCG 259 Now I need to count A/T/G/C numbers at each character location in column... (2 Replies)
Discussion started by: thienxho
2 Replies

9. Shell Programming and Scripting

[Solved] If doesn't evaluate the first test

Good afternoon, I am tearing hair out over this. It should be so simple. I have an if statement to evaluate whether or not replication is working. I am testing variables from mysql to see if they are both "Yes". I have put some echo statements in to see how far the code proceeds. It always... (6 Replies)
Discussion started by: jimm
6 Replies

10. Shell Programming and Scripting

Test command non case specific string comparision

Hi, I want to do caseless string comparision using test command for eg: Ind_f="y" test "$Ind_f" == "y|Y" i tried , ** , nothing worked. any thoughts on how to do case insensitive string comparison using test command without converting to any particular case using typeset or tr? (8 Replies)
Discussion started by: Kulasekar
8 Replies
SETLOCALE(3)								 1							      SETLOCALE(3)

setlocale - Set locale information

SYNOPSIS
string setlocale (int $category, string $locale, [string $...]) DESCRIPTION
string setlocale (int $category, array $locale) Sets locale information. PARAMETERS
o $category -$category is a named constant specifying the category of the functions affected by the locale setting: o LC_ALL for all of the below o LC_COLLATE for string comparison, see strcoll(3) o LC_CTYPE for character classification and conversion, for example strtoupper(3) o LC_MONETARY for localeconv(3) o LC_NUMERIC for decimal separator (See also localeconv(3)) o LC_TIME for date and time formatting with strftime(3) o LC_MESSAGES for system responses (available if PHP was compiled with libintl) o $locale - If $locale is NULL or the empty string "", the locale names will be set from the values of environment variables with the same names as the above categories, or from "LANG". If $locale is "0", the locale setting is not affected, only the current setting is returned. If $locale is an array or followed by additional parameters then each array element or parameter is tried to be set as new locale until success. This is useful if a locale is known under different names on different systems or for providing a fall- back for a possibly not available locale. o $... - (Optional string or array parameters to try as locale settings until success.) Note On Windows, setlocale(LC_ALL, '') sets the locale names from the system's regional/language settings (accessible via Control Panel). RETURN VALUES
Returns the new current locale, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid. An invalid category name also causes a warning message. Category/locale names can be found in RFC 1766 and ISO 639. Different systems have different naming schemes for locales. Note The return value of setlocale(3) depends on the system that PHP is running. It returns exactly what the system setlocale function returns. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 7.0.0 | | | | | | | Support for the $category parameter passed as a | | | string has been removed. Only LC_* constants can | | | be used as of this version. | | | | | 5.3.0 | | | | | | | This function now throws an E_DEPRECATED notice | | | if a string is passed to the $category parameter | | | instead of one of the LC_* constants. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 setlocale(3) Examples <?php /* Set locale to Dutch */ setlocale(LC_ALL, 'nl_NL'); /* Output: vrijdag 22 december 1978 */ echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978)); /* try different possible locale names for german as of PHP 4.3.0 */ $loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); echo "Preferred locale for german on this system is '$loc_de'"; ?> Example #2 setlocale(3) Examples for Windows <?php /* Set locale to Dutch */ setlocale(LC_ALL, 'nld_nld'); /* Output: vrijdag 22 december 1978 */ echo strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978)); /* try different possible locale names for german as of PHP 4.3.0 */ $loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu'); echo "Preferred locale for german on this system is '$loc_de'"; ?> NOTES
Warning The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS, HHVM or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called setlocale(3). This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale(3). Tip Windows users will find useful information about $locale strings at Microsoft's MSDN website. Supported language strings can be found in the language strings documentation and supported country/region strings in the country/region strings documentation. PHP Documentation Group SETLOCALE(3)
All times are GMT -4. The time now is 04:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy