Hi,
I have a simple question... In C do we have a standard library function which will return the pointer to a substring at certain offset and having certain length...
Ofcourse we should take care not to access beyond allocated length in the parent string and don't overwrite beyond allocated... (2 Replies)
I'm only new to shell programming and have been given a task to do a program in .sh, however I've come to a point where I'm not sure what to do. This is my code so far:
# process all arguments (i.e. loop while $1 is present)
while ; do
# echo "Arg is $1"
case $1 in
-h*|-H*) echo "help... (4 Replies)
I have a very long string (millions of characters).
I have a file with start location and length that is thousands of rows long:
Start Length
5 10
16 21
44 100
215 37
...
I'd like to extract the substring that corresponds to the start and length from each row of the list:
I tried... (7 Replies)
In AIX 4.2, are there any shell commands to do substrings and the text like manipulation commands ?
I want to take an error log where errors are multi-ligned and convert them into single lines to ease tracking/monitoring. I may need to shorten them out too.
If I can manage to put them into an... (2 Replies)
Hello Everyone,
I am looking for a way to extract substrings to local variables. Here is the format of the string variable i am using :
/var/x/www && /usr/x/share/doc && /etc/x/logs
where the substrings i must extract are the "/var/x/www" and such.
I was originally thinking of using... (15 Replies)
Hi !
my input looks like that:
--AAA-AAAAAAA---------AA-
AAA------AAAAAAAAAAAAAA
------A----AAAA-----A-------
Using awk, I would need to replace only the "-" located between the last letter and the end of the string by "~"
in order to get:
--AAA-AAAAAAA---------AA~... (7 Replies)
I have a string like
Months=jan feb mar april x y ..
Here the number of fields in Months is not definite
I need to extract each field in the Months string and pass it to awk . Don't want to use for in since it is a loop . How can i do it (2 Replies)
Hello, I would like to know what is the three most abundant substrings of length 6 from col2. The file is quite large and looks like this
col1 col2
EN03 typehellobyedogcatcatdog
EN09 typehellobyebyebyebye
EN08 dogcatcatdogbyebyebyebye
EN09 catcattypehellobyebyebyebye... (9 Replies)
Hello gurus,
I have a lookup table
cat tmp1
\\\erw``~ 1
^774574574565665f\] 2
()42543^
and I`m trying to compare a bunch of strings such that, either the lookup table column 1, or the string to be looked up are substrings of each other (and return the second lookup column if yes).
... (2 Replies)
Discussion started by: sheetalk
2 Replies
LEARN ABOUT PHP
ereg
EREG(3) 1 EREG(3)ereg - Regular expression matchSYNOPSIS
int ereg (string $pattern, string $string, [array &$regs])
DESCRIPTION
Searches a $string for matches to the regular expression given in $pattern in a case-sensitive way.
Warning
This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
PARAMETERS
o $pattern
- Case sensitive regular expression.
o $string
- The input string.
o $regs
- If matches are found for parenthesized substrings of $pattern and the function is called with the third argument $regs, the
matches will be stored in the elements of the array $regs. $regs[1] will contain the substring which starts at the first left
parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of the complete
string matched.
RETURN VALUES
Returns the length of the matched string if a match for $pattern was found in $string, or FALSE if no matches were found or an error
occurred.
If the optional parameter $regs was not passed or the length of the matched string is 0, this function returns 1.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 4.1.0 | |
| | |
| | Up to (and including) PHP 4.1.0 $regs will be |
| | filled with exactly ten elements, even though |
| | more or fewer than ten parenthesized substrings |
| | may actually have matched. This has no effect on |
| | ereg(3)'s ability to match more substrings. If no |
| | matches are found, $regs will not be altered by |
| | ereg(3). |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
ereg(3) example
The following code snippet takes a date in ISO format (YYYY-MM-DD) and prints it in DD.MM.YYYY format:
<?php
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
echo "$regs[3].$regs[2].$regs[1]";
} else {
echo "Invalid date format: $date";
}
?>
NOTES
Note
As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED
notice. See the list of differences for help on converting to PCRE.
Tip
ereg(3) is deprecated as of PHP 5.3.0. preg_match(3) is the suggested alternative to this function.
SEE ALSO eregi(3), ereg_replace(3), eregi_replace(3), preg_match(3), strpos(3), strstr(3), quotemeta(3).
PHP Documentation Group EREG(3)