Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Podział ciągu na tablice, Wyrażenie regularne
perhydrol
post
Post #1





Grupa: Zarejestrowani
Postów: 50
Pomógł: 0
Dołączył: 11.12.2006

Ostrzeżenie: (0%)
-----


Witam,

słabo mi idzie z wyrażeniami regularnymi więc mam problem z podziałem ciągu znaków na tablice
wydaje mi się że sensownie było by zamienić wystąpienie wielu spacji na tabulator, i wtedy dopiero podział ciągu na tablice po wystąpieniu \t

tylko jak zbudować wyrażenie regularne dla wystąpienia wielu spacji, nie zawsze o równej długości, pomijając wystąpienie jednej (IMG:style_emoticons/default/questionmark.gif)

Przykładowy ciąg:
  1. 1234567890 aaaassdsdasd jkjkjkj klkklk lkllk 2323233
  2. 5464567834 hgfhaassdsdasd sdfsdfkjkj dsfsdfklk fghfgffllk 5623233



Go to the top of the page
+Quote Post
thek
post
Post #2





Grupa: Moderatorzy
Postów: 4 362
Pomógł: 714
Dołączył: 12.02.2009
Skąd: Jak się położę tak leżę :D




Może kombinując z preg_replace i zamianą [:space:]{2, } na ' '
Go to the top of the page
+Quote Post
perhydrol
post
Post #3





Grupa: Zarejestrowani
Postów: 50
Pomógł: 0
Dołączył: 11.12.2006

Ostrzeżenie: (0%)
-----


[:space:] czyli [\s] ?



Ten post edytował perhydrol 24.03.2010, 09:56:09
Go to the top of the page
+Quote Post
thek
post
Post #4





Grupa: Moderatorzy
Postów: 4 362
Pomógł: 714
Dołączył: 12.02.2009
Skąd: Jak się położę tak leżę :D




:space: w wyrażeniach regularnych oznacza znaki puste. Nie tylko spacje, ale choćby też tabulatory czy znaki końca linii. Zgodnie z POSIX cytuję:
Cytat
POSIX Character Class Definitions

POSIX 1003.2 section 2.8.3.2 (6) defines a set of character classesthat denote certain common ranges. They tend to look very ugly but have the advantage that also take into account the 'locale', that is, any variant of the local language/coding system. Many utilities/languages provide short-hand ways of invoking these classes. Strictly the names used and hence their contents reference the LC_CTYPE POSIX definition (1003.2 section 2.5.2.1).

[:digit:] Only the digits 0 to 9
[:alnum:] Any alphanumeric character 0 to 9 OR A to Z or a to z.
[:alpha:] Any alpha character A to Z or a to z.
[:blank:] Space and TAB characters only.
[:xdigit:] Hexadecimal notation 0-9, A-F, a-f.
[:punct:] Punctuation symbols . , " ' ? ! ; : # $ % & ( ) * + - / < > = @ [ ] \ ^ _ { } | ~
[:print:] Any printable character.
[:space:] Any whitespace characters (space, tab, NL, FF, VT, CR). Many system abbreviate as \s.
[:graph:] Exclude whitespace (SPACE, TAB). Many system abbreviate as \W.
[:upper:] Any alpha character A to Z.
[:lower:] Any alpha character a to z.
[:cntrl:] Control Characters NL CR LF TAB VT FF NUL SOH STX EXT EOT ENQ ACK SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC IS1 IS2 IS3 IS4 DEL.

These are always used inside square brackets in the form [[:alnum:]] or combined as [[:digit:]a-d]
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 12.10.2025 - 11:34