firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.2k stars 198 forks source link

PHP code generator uses single quotes #2174

Closed theking2 closed 4 months ago

theking2 commented 8 months ago

Bug Description

The PHP generator uses single quotes which clash with the single quoted name groups

Reproduction steps

https://regex101.com/r/wboOmg/1/codegen?language=php

$re = '/Report_(?\'type\'[0-9]{3})_(?\'name\'[A-Za-z_]*)(?:_V(?\'version\'\d))?_[a-zA-Z_]*.*(?\'date\'\d{4}\.\d{2}\.\d{2})\.(?\'time\'\d{2}\.\d{2}\.\d{2}).*\.csv/m';
$str = 'Report_100_Sales_V1_Guerbet_2023_10_02-2023_10_17_2023.10.18.04.57.54.csv
Report_100_Sales_V1_Guerbet_2023_10_02-2023_10_18_2023.10.19.04.56.38.csv
Report_104_OpenOrders_V1_Guerbet_2023_10_17_2023.10.18.04.57.20.csv
Report_200_Movements_V1_Guerbet_2023_10_02-2023_10_17_2023.10.18.04.36.54.csv
Report_200_Movements_V1_Guerbet_2023_10_17_2023.10.18.04.55.05.csv
Report_300_Stock_V1_Guerbet_2023_10_17_2023.10.18.04.57.04.csv
Report_302_StockNotification_V1_Guerbet_2023_10_17_2023.10.18.04.56.08.csv
Report_400_Returns_V1_Guerbet_2023_09_01-2023_09_30_2023.10.18.04.54.37.csv
Report_502_BaseData_Material_V1_Guerbet_2023_10_17_2023.10.18.04.57.25.csv
Report_503_BaseData_Customers_V1_Guerbet_2023_10_17_2023.10.18.04.57.30.csv
Report_700_Invoices_V1_Guerbet_2023_10_17_2023.10.18.04.57.32.csv';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result
var_dump($matches);

Expected Outcome

$re = "/Report_(?\'type\'[0-9]{3})_(?\'name\'[A-Za-z_]*)(?:_V(?\'version\'\d))?_[a-zA-Z_]*.*(?\'date\'\d{4}\.\d{2}\.\d{2})\.(?\'time\'\d{2}\.\d{2}\.\d{2}).*\.csv/m";

Browser

Include browser name and version Any

OS

Include OS name and version Any

firasdib commented 4 months ago

What is the actual problem? The generated code should still work. Please reopen if you still feel this is a problem.