4

Regex recruit needs help

 2 years ago
source link: https://www.codesd.com/item/regex-recruit-needs-help.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Regex recruit needs help

advertisements

I'm totally useless at regex, any advice much appreciated.

$url = 'http://somedomain.com?var=<##var##>&var2=<##var2##>';
echo preg_replace('^<##(.*)##>$', '', $url);

Trying to strip anything between (and including) <## and ##>. So my result would be:

http://somedomain.com?var=&var2=

Thanks


The code should be:

<?php
$url = 'http://somedomain.com?var=<##var##>&var2=<##var2##>';
$newUrl = preg_replace('/<##.*?##>/', '', $url);
echo $url;
?>

The ^ and $ you used are wrong, they represend the begin or the end of the string and you won't replace only the <##...##> part if <## is at the beginning and ##> at the end of the string.

Also the ? after .* means that it matches everything from the <## until the next ##>. If you use .* it matches everything from the first <## until the last ##> so you result would be http://somedomain.com?var=

Related Articles

Need help getting parts of an RSS feed using Regex

I'd need to to extract the company name (JTA Connection) before the first and the deadline and location, preferably without the "Deadline:" and "Location:" parts, from the RSS feed below using REGEX. <description>JTA Connection O

Need help with (hopefully) simple RegEx

I am brand new to using RegEx's and need a bit of a jump start to get the ball rolling. The RegEx I need is, hopefully, pretty simple. All it needs to do is verify that the text entered follows the following format: 00.000 (2 digits, a period, 3 digi

I need help decoding this regular expression of the sprockets

I need help decoding this regular expression from sprockets. I am not sure what this matches but if someone give give me some hints or starting points. HEADER_PATTERN = / \A ( (?m:\s*) ( (\/\* (?m:.*?) \*\/) | (\#\#\# (?m:.*?) \#\#\#) | (\/\/ .* \n?)

Need help with the sql query to find things labeled with all the specified tags

Let's say I have the following tables: TAGS id: integer name: string POSTS id: integer body: text TAGGINGS id: integer tag_id: integer post_id: integer How would I go about writing a query that select all posts that are tagged with ALL of the followi

I need help with a SQL query JOINT JOIN

I need help to write a simple procedure. Let me explain what I'm trying to do. I have 3 tables tJobOffer tApplication tApplicationStatus I would like to create a procedure that return me a list of tJobOffer with the number of candidate that responded

Java: Need help reporting NullPointerException

Need help pointing out which one causes the NullPointerException. I've tried everything from what I understand but still no luck. import com.threed.jpct.Object3D; public class HelloShader extends Activity implements OnScaleGestureListener { private f

Need help writing a custom attribute in MVC

I have to write custom attribute to check dependent property using MVC pattern. I am using System.ComponentModel.DataAnnotations for checking required fields. My WPF application contains listview control. All my properties written in modal class get

Need help optimizing the oracle query

I need help in optimizing the following query. It is taking a long time to finish. It takes almost 213 seconds . because of some constraints, I can not add an index and have to live with existing ones. INSERT INTO temp_table_1 ( USER_ID, role_id, par

I need help understanding the manipulation of the character

Question: I need to write a function, int is_lower_101(char c), that returns true if it's a lowercase and false otherwise. And I can't use the predefined tolower type functions. I also can't use integer values for the characters. What I need help wit

Need help for complex data to sort SQL Server

I need help for complex data sort from database. Suppose my data stored in table like this: Description -------------- JCB Excavator - ECU P/N: 728/35700 Geo Prism 1995 GEO - ABS #16213899 GEO pump Geo Prism 1995 - GEO ABS #16213897 Geo Prism 1995 -

Need help with forming a regular expression -xml

How can I form a regex for xml where it can accept any alphabet except K, I, L or any digit between 0 to 9 and the length should be 1. Below is one way. [0-9 ABCDEFGHJMNOPQRST]{1} How can i shorten this regex? Kindly help.The regex should look someth

Need help repositioning and resizing widgets with the Python Tkinter grid

Hi guys I was wondering if I could get some help on how to resize widgets with .grid on tkinter. I have no clue and I've tried weight= but it doesn't do anything. I also need help moving the two combo boxes in my code to certain areas. Normally the w

Need help creating lead or corner divisions CSS / HTML

I need help creating responsive divs with background images that have a slant or angle in them with no border to achvive a look like this: http://jsfiddle.net/b4zjs60k/ <div class="rr-left"> </div> <div class="rr-right"&

Program file (x86) when checked for dwfileattributes Returns a value of 73745. I need help knowing what combination is added to this value?

WIN32_FIND_DATA FindFileData; . . . . if(FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { . } This failed for program files and I found it online that it is combination of FILE_ATTRIBUTE_DIRECTORY + FILE_ATTRIBUTE_READONLY and not FILE_AT

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK