473,224 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Regular expressions: problems with swedish characters

Hi,

I've got a problem with regular expressions and strings containing
Swedish characters ().

I basically have a PHP script that highlights certain words in a text. I
found the code attached below in the commented manual at php.net. It
works great for all words that do not contain Swedish characters. The
words that do contain will not be highlighted.

Can anyone suggest how I should change my regexp to fix this?

Thanks,
toffe

Code:
=============
function highlightErrors($text, $errors) {

foreach($errors as $e) {
$text = highlight_word($text,$e);
}

return $text;
}

function highlight_word($buff,$query) {

$buff = preg_replace("/(^|[^A-Z]){1}(".preg_quote($query,"/").
")($|[^A-Z]){1}/i",
"\\1<span class='highlight'>\\2</span>\\3", $buff);
return $buff;
}

=========
Jul 17 '05 #1
4 8156
Q: How could I match the foreign characters like in regular
expressions?
A: Use hexadecimal representation of those characters, like \xe1

Refer:
http://www.php.net/preg_match#42167

Jul 17 '05 #2
R. Rajesh Jeba Anbiah wrote:
Q: How could I match the foreign characters like in regular
expressions?
A: Use hexadecimal representation of those characters, like \xe1

Refer:
http://www.php.net/preg_match#42167


Sorry for being ignorant and not reading the FAQ before posting, won't
happen again...

Thanks a lot for the information!

-toffe
Jul 17 '05 #3
R. Rajesh Jeba Anbiah wrote:
Q: How could I match the foreign characters like in regular
expressions?
A: Use hexadecimal representation of those characters, like \xe1

Refer:
http://www.php.net/preg_match#42167


Hi, thanks for the pointer.

It works almost like I want it to now.
My script should highlight certain words in the text, but the text could
be a mix of upper and lower case letters, and if $query below is hxllo
and $buff is HXLLO, where x and X is some Swedish character in its lower
and upper cases, I still don't get a match.

Any suggestions for how I can fix this?

Thanks,
toffe

Code:
====

$buff =
preg_replace("/(^|[^A-Z\xe5\xe4\xf6\xc5\xc4\xd6]){1}(".preg_quote($query,"/").
")($|[^A-Z\xe5\xe4\xf6\xc5\xc4\xd6]){1}/i",
"\\1<SURROUNDING>\\2<TAG>\\3", $buff);

return $buff;
=========
Jul 17 '05 #4
Toffe wrote:
R. Rajesh Jeba Anbiah wrote:
Q: How could I match the foreign characters like in regular
expressions?
A: Use hexadecimal representation of those characters, like \xe1

Refer:
http://www.php.net/preg_match#42167
It works almost like I want it to now.
My script should highlight certain words in the text, but the text

could be a mix of upper and lower case letters, and if $query below is hxllo and $buff is HXLLO, where x and X is some Swedish character in its lower and upper cases, I still don't get a match. <snip> Code:
====

$buff =
preg_replace("/(^|[^A-Z\xe5\xe4\xf6\xc5\xc4\xd6]){1}(".preg_quote($query,"/"). ")($|[^A-Z\xe5\xe4\xf6\xc5\xc4\xd6]){1}/i",
"\\1<SURROUNDING>\\2<TAG>\\3", $buff);

return $buff;
=========


IIRC, there is no lower-upper case distinction for the foreign
characters--so you may have to add those upper/lower case characters in
the set. Probably you may need to look at
<http://in.php.net/ucwords#51137>

BTW, we don't have any FAQ yet. We're just compiling and the
question was asked previously.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
15
by: Roz Lee | last post by:
I am trying to work out a regular expression which will validate a password box. The following rules apply Must be 8 characters Must have at least one digit (0-9) and at least one character...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
9
by: Mike P | last post by:
I have a regular expression that I use on text boxes where I want to limit the user to letters a-z and spaces. I now need to allow characters such as , and (Nordic characters). Does anybody...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
15
by: Mark Rae | last post by:
Hi, I'm trying to construct a RegEx pattern which will validate a string so that it can contain: only the numerical characters from 0 to 9 i.e. no decimal points, negative signs, exponentials...
1
by: tshad | last post by:
Some of my regular expressions don't seem to work correctly in IE7. I am on asp.net 1.1. I have a site that has been up for a while and I started having problems on machines with IE7. IE5 and...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.